Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- input data:
- 7 1 199999 4 # são os índices da list imaginária
- answer:
- 19 3 2750131 11 # são os primos dessa list, correspondentes aos índices acima
- from math import sqrt
- def primos(n, maxIndex):
- maiorCheck = int(sqrt(n))
- lista = []
- i, x, qtdPrimos = 0, 0, 0
- for m in range(2, n+1):
- lista.append(m)
- while x <= maiorCheck:
- x = lista[i]
- i += 1
- for numero in lista:
- if numero != x:
- if numero % x == 0:
- lista[lista.index(numero)] = 0
- while 0 in lista:
- del lista[lista.index(0)]
- if len(lista) == maxIndex:
- x = maiorCheck + 1
- return lista
- qtdPrimos = int(input('Entre com a quantidade de primos a serem impressos: ').strip())
- indexes = input('Entre com os índices para os quais serão retornados primos: ').strip().split()
- result = []
- for n in range(len(indexes)):
- indexes[n] = int(indexes[n])
- arrayPrimos = primos(2750131, max(indexes))
- for m in range(len(indexes)):
- result.append(str(arrayPrimos[indexes[m]-1]))
- print('n--- R E S U L T A D O ---n'+' '.join(result))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement