Skip to content

Instantly share code, notes, and snippets.

@moacirmoda
Created August 23, 2017 18:56
Show Gist options
  • Save moacirmoda/e87cb91d59250bbd113b0dde9b0833b1 to your computer and use it in GitHub Desktop.
Save moacirmoda/e87cb91d59250bbd113b0dde9b0833b1 to your computer and use it in GitHub Desktop.
Cálculo de números primos
# http://dojopuzzles.com/problemas/exibe/geracao-de-fatores-primos/
i = 10000
primos = []
for y in range(1, i+1):
is_primo = True
for x in range(y, i+1):
if y % x == 0 and x > 1 and x != y:
is_primo = False
break
if is_primo:
primos.append(y)
value = i
index = 0
while True:
primo = primos[index]
if primo > 1:
if value % primo == 0:
value = value/primo
print(primo, value)
continue
if value == 1 or not value:
break
index += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment