Created
August 15, 2014 19:19
-
-
Save mathiasose/ac9028642677bbb11022 to your computer and use it in GitHub Desktop.
This file contains 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
from random import randint | |
def is_prime(n): | |
return False if n <= 1 else not any(n % x == 0 for x in range(2, int(n ** 0.5) + 1)) | |
def biggest_prime_factor(n): | |
''' | |
intentionally not using recursion | |
''' | |
while n % 2 == 0: | |
if n == 2: | |
return 2 | |
n /= 2 | |
if is_prime(n): | |
return n | |
p = 3 | |
while True: | |
if n % p == 0 and is_prime(p): | |
n /= p | |
if is_prime(n): | |
return n | |
else: | |
p += 2 | |
for num in (randint(3, 600851475143) for _ in xrange(10)): | |
print num, | |
print '\t', | |
print biggest_prime_factor(num) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment