Beispiel #1
0
Datei: 360t.py Projekt: qhool/pe
def can_sqsum(n):
    max_p = int(n/2)
    max_p_if_prime = int(sqrt(n))
    primes = primes_generator()
    p = primes.next()
    mult = 0
    is_prime = True
    while True:
        if n % p == 0:
            mult += 1
            print n, "/", p
            n /= p
            if n == 1:
                break
        else:
            if mult > 0:
                if p % 4 == 3 and mult % 2 == 1:
                    return False
                is_prime = False
            p = primes.next()
            #print p
            mult = 0
            if p > max_p or (is_prime and p > max_p_if_prime):
                break
    return True
Beispiel #2
0
Datei: 051.py Projekt: qhool/pe
#!/usr/bin/env python
from math import log10, ceil
import funcs
import string

max_set = 0
for p in funcs.primes_generator():
    strp = str(p)
    #print strp
    for d in set( strp ):
        primeset = []
        digits = range(10)
        if strp[-1] == d:
            digits = range(1,10,2)
        for d2 in digits:
            if d == d2:
                continue
            p2 = string.replace( strp, d, str(d2) )
            if p2[0] == '0':
                continue
            p2 = int(p2)
            if funcs.is_prime( p2 ):
                primeset.append(p2)
        if len(primeset) > max_set:
            max_set = len(primeset)
            print "{0} {1} ---> {2}".format( max_set, p, primeset )
            if max_set >= 8:
                exit()
Beispiel #3
0
Datei: 360t.py Projekt: qhool/pe
                if p % 4 == 3 and mult % 2 == 1:
                    return False
                is_prime = False
            p = primes.next()
            #print p
            mult = 0
            if p > max_p or (is_prime and p > max_p_if_prime):
                break
    return True


r = 10**10
rsq = r**2
print "pre-gen-primes"
max_p = r/2
for p in primes_generator():
    if p >= max_p:
        break
    print p
print "done"

    
i = 0
while i < r:
    slice_rsq = rsq - i**2
    if sqrt(slice_rsq) % 1 == 0:
        print slice_rsq
        if can_sqsum( slice_rsq ):
            print "  Yes"
    i+=1