예제 #1
0
import primality, sys
from itertools import *
from functools import *

N = 100
primes = primality.primes(N)
nums = [False,]*N
nums[1] = 1,
for p in primes:
    if p > N:
        break

    basket = [False,]*N
    n = 1
    while p**n < N:
        for c in filter(lambda x: x, nums):
            getvalue = lambda parts : reduce(lambda acc, part: acc * part, parts, 1)
            v = tuple(chain(c, (p,)*n))
            val = getvalue(v)
            if val >= N:
                break
            basket[val] = v
        n += 1

    for i, n in filter(lambda x: x[1], enumerate(basket)):
        nums[i] = n

"""for n, p in enumerate(nums):
    if p:
        print n, reduce(lambda s, v: s + " %i"%(v,), p, "")"""
예제 #2
0
파일: conquad.py 프로젝트: genjix/random
import primality, itertools

def countprimes(primes, a, b):
    score = 0
    for n in itertools.count():
        if n**2 + a*n + b not in primes:
            return score
        score += 1

primes = primality.primes(10000)
hiscore = 0, 0, 0
for a in range(-1000,1001):
    for b in range(-1000,1001):
        sc = countprimes(primes, a, b)
        if sc > hiscore[0]:
            hiscore = sc, a, b
print(hiscore)