示例#1
0
 def __init__(self, n, primelist=None):
     self.number = n
     self.target = n
     self.current = 2
     if primelist:
         self.primes = primelist
     else:
         prime = sieve(n)
         self.primes = [x for x in xrange(n) if prime[x]]
     self.primeIter = ifilter(None, self.primes)
示例#2
0
from sievebool import sieve

prime = sieve(1000000)
primes = [x for x in xrange(len(prime)) if prime[x]]

def primefactors(n):
    if n in primes:
        return {n: 1}
    factors = {}
    target = n
    for x in primes:
        if x > target:
            break
        mult = 0
        if not n % x:
            while not n % x:
                mult += 1
                n /= x
            factors[x] = mult
    return factors
示例#3
0
from sievebool import sieve

primes = sieve(1000000)
primes = set([x for x in xrange(len(primes)) if primes[x]])

def lenseries(a, b):
    if b not in primes: return 0
    
    count = 0
    
    while (True):
        if count**2 + a*count + b not in primes: break
        count += 1
    return count
    
maxlength = 0

prod = 0

for a in xrange(-999, 1000):
    for b in xrange(-999, 1000):
        length = lenseries(a, b)
        if length > maxlength:
            maxlength = length
            prod = a * b
            
print prod
示例#4
0
from sievebool import sieve

print "Building primes..."
primes = sieve(1000000)
primelist = []
for x in xrange(len(primes)):
    if primes[x]:
        primelist.append(x)

def istruncatableL(n):
    n = str(n)[1:]
    while n:
        if not primes[int(n)]:
            return False
        n = n[1:]
    return True
    
def istruncatableR(n):
    n /= 10
    while n > 0:
        if not primes[n]:
            return False
        n /= 10
    return True
        

count = 0
total = 0
print "Testing..."
for x in primelist:    
    if istruncatableL(x) and istruncatableR(x):
示例#5
0
文件: distinct.py 项目: ukscone/code
from sievebool import sieve

prime = sieve(1000000)
primes = [x for x in xrange(len(prime)) if prime[x]]


def primefactorset(n):
    factors = set()
    for x in primes:
        if x > n / 2:
            break
        if not n % x:
            factors.add(x)
    return factors


def istheanswer(x):
    if len(primefactorset(x)) != 4:
        return False
    if len(primefactorset(x + 1)) != 4:
        return False
    if len(primefactorset(x + 2)) != 4:
        return False
    if len(primefactorset(x + 3)) != 4:
        return False
    return True


x = 1
while not istheanswer(x):
    x += 1