def p46(): #getting precalculated primes and squares: u = Utils() primes = u.sieve(6000) squares = [i * i for i in range(1, 101)] #start searching at 15: o = 15 while o < 5800: #is the test number prime? if u.chop(o, primes) != -1: #yeap, go to next one: o += 2 continue #nope, begin testing: ind = 0 found = False while o - primes[ind] > 0: s = (o - primes[ind]) / 2 #found desired decomposition? if u.chop(s, squares) != -1: #yep, break out: found = True break #nope, try next prime: else: ind += 1 #found possible candidate: if not found: print o #keep searching: o += 2
def p44(): u = Utils() limit = 3000 pl = [u.pentagonal(i) for i in xrange(limit)] for a in xrange(1, limit): for b in xrange(1, limit): if a > b: c = pl[a] + pl[b] d = pl[a] - pl[b] if u.chop(c, pl) > -1 and u.chop(d, pl) > -1: print a, b, pl[a], pl[b],\ pl[pl.index(c)],\ pl.index(c),\ pl[pl.index(d)],\ pl.index(d)