Beispiel #1
0
#!/usr/bin/env python

from math import sqrt
from util import primes

if __name__ == "__main__":
    target = 600851475143
    factor_candidates = primes.filter_lt(int(sqrt(target)))

    factors = [ x for x in factor_candidates if target % x == 0 ]
    print factors[-1]
Beispiel #2
0
#!/usr/bin/env python

from operator import add
from util import primes

if __name__ == "__main__":
    target = 2000000
    primes_lt_target = primes.filter_lt(target)

    print reduce(add, primes_lt_target)
Beispiel #3
0
from util import primes
from collections import defaultdict
from itertools import permutations 

def rotations(orig):
    yield orig
    cur = orig[-1]+orig[:-1]
    while cur != orig:
        yield cur
        cur = cur[-1]+cur[:-1]

if __name__ == "__main__":
    target = 1000000 # a milli
    comb_count = defaultdict(int)

    circular_set = set()

    pr_set = set(primes.filter_lt(target))
    print 'total primes len:',len(pr_set)
    for i in pr_set:
        rot_set = set([int(x) for x in rotations(str(i))])
        if( rot_set & pr_set == rot_set ):
            circular_set = circular_set | rot_set

        # if you could modify pr_set while iterating over it,
        # you could optimize to not check for other primes 
        # in the current rot_set

    print 'circ primes len:',len(circular_set)