Last active
August 29, 2015 13:56
-
-
Save mtayseer/8848148 to your computer and use it in GitHub Desktop.
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
def sieve(numbers, n): | |
for i in range(n * 2, len(numbers), n): | |
numbers[i] = False | |
def skip_to_next_prime(numbers, n): | |
n += 1 | |
while n < max and not numbers[n]: | |
n += 1 | |
return n | |
def primes(max): | |
'''generate primes less than max''' | |
max = int(max ** .5) | |
numbers = [False, False] + [True] * max | |
n = 2 | |
while n < max: | |
sieve(numbers, n) | |
n = skip_to_next_prime(numbers, n) | |
return [i for i in range(max) if numbers[i]] | |
#n = 13195 | |
n = 600851475143 | |
print [x for x in primes(n) if n % x == 0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment