Beispiel #1
0
def solve():
    even_char = re.compile("0|2|4|6|8")
    sum_all = 0
    count = 0
    for i in primes_in_range(9,1000000,2):
        s = str(i)
        if '0' in s:
            continue
#       if even_char.search(s):
#           continue
#       else:
        flag = True
        for sub in truncl(s):
            if not isprime(int(sub)):
                flag = False
                break
        if flag:
            for sub in truncr(s):
                if not isprime(int(sub)):
                    flag = False
                    break
        if flag: 
            count += 1
            sum_all += i
            print '*** PING ***   ', i
    print "Answer: first %i primes add up to %i" % (count, sum_all)
Beispiel #2
0
def solve():
    c = 0
    for n in primes_in_range(2, 1000000, 1):
        flag = True
        for r in rots(n):
            if not isprime(r):
                flag = False
                break
        if flag:
            c += 1
            print "%i (%i)" % (n, c)
Beispiel #3
0
    print n-1

if __name__=="__main__":
##    for s in solutions(4):
##        print '1/%i + 1/%i = 1/%i' % s
    assert solutions(4) == 3
    
    if 0:
        import cProfile
        cProfile.run('solve()')
    elif 0:
        f = factorial(12)
        f2 = factorial(13)
        print f, f2
        print f2 - f
        print len([n for n in primes_in_range(f+1, f+10000)])
    elif 0:
        factor_search(50)
    elif 1:
        solve(1000000)
    elif 0:
        import time
        def cfs():
            c = 1
            vals = []
            while c < 10000:
                vals.append(count_factors(c))
                c += 1
            return vals
        def sols():
            c = 1