Created
August 23, 2017 18:56
-
-
Save moacirmoda/e87cb91d59250bbd113b0dde9b0833b1 to your computer and use it in GitHub Desktop.
Cálculo de números primos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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