Skip to content

Instantly share code, notes, and snippets.

@bbeckercontato
Created February 6, 2016 00:15
Show Gist options
  • Save bbeckercontato/9c05b967699838306531 to your computer and use it in GitHub Desktop.
Save bbeckercontato/9c05b967699838306531 to your computer and use it in GitHub Desktop.
Gerador de números primos no conjunto de phi(42*n)
limite = int(input("Digite limite: "))
contador = 0
base2=[]
primos=[]
base = [ 1, 5, 11, 13, 17, 19, 23, 25, 29, 31, 37, 41]
pa=[]
import time
t0 = time.time()
arq = open("Primos.html", "w")
while limite > base[-1]:
for b in base:
if b%5 != 0:
base2.append(b)
base = [s+42 for s in base]
base2.remove(1)
limite2 = base2[-1]
for r in base2:
x = r
y = r
while x <= limite2 and x <= y*y:
for temp in [4, 6, 2, 4, 2, 4, 2, 4, 2, 6, 4, 2]:
x += y*temp
if x > y*y or x > limite2: break
elif x%5 != 0: pa.append(x)
base2.append(2)
base2.append(3)
base2.append(5)
base2.append(7)
primos = ((sorted(set(base2) - set(pa))))
arq.write(str(primos))
arq.close()
tf = time.time()
print("\n")
print("Tempo executado: ",tf - t0)
print("\n")
print("Foi gerado lista em arquivo de texto no local do programa")
print("\n")
input("Pressione ENTER para SAIR")
#Teoria matemática de Bruno Becker [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment