Ejemplo n.º 1
0
def find1():
    # take so long
    for n in genprime():
        if ispandigital(n):
            print n
        if n > 987654321:
            break
Ejemplo n.º 2
0
def sum1(n):
    # a bit slow
    s=0
    for p in genprime():
        if p > n:
            break
        s+=p
    return s
Ejemplo n.º 3
0
def goldbach():
    gp = genprime()
    p = gp.next()
    q = gp.next()

    while True:
        for com in xrange(p+2,q,2):
            if not isop(com):
                return com
        p = q
        q = gp.next()
Ejemplo n.º 4
0
def findmostCP(LIMITS):
    primes = []
    sop = 0
    gp = genprime()

    while sop < LIMITS:
        p = gp.next()
        primes.append(p)
        sop += p

    for n in range(1,len(primes)):
        for i in range(n+1):
            s = sum(primes[i:len(primes)-n+i])
            if s < LIMITS and isprime(s):
                return s
Ejemplo n.º 5
0
def findR2(a, b):
    # phi = pi(n*(1-1/p))
    gp = genprime()
    r, l = b, a
    d = 1
    while True:
        p = gp.next()
        rn = r * (p - 1)
        ln = l * p
        dn = d * p
        # find the most 2*3*5*...value
        if rn * dn < ln * (dn - 1):
            # test small values
            for i in xrange(2, p):
                if r * d * i < l * (d * i - 1):
                    return d * i
        r = rn
        l = ln
        d = dn

    return 0
Ejemplo n.º 6
0
        if n!=s:
            return False
    return True

def isperm(l):
    if len(l) < 1:
        return False
    k = [sorted(str(i)) for i in l]
    d = k[0]
    for p in k:
        if p != k:
            return False
    return True
    

primedic = {}
for n in genprime():
    if n > 10000:
        break
    if n > 1000:
        s = int(''.join(sorted(str(n))))
        if s not in primedic:
            primedic[s] = []
        primedic[s].append(n)

for numsl in primedic.values():
    for nums in combinations(numsl,3):
        if isacc(nums):
            print nums

Ejemplo n.º 7
0
#! /usr/bin/env python

from eulerutils import genprime,ispermutation
from sys import exit

primes = []
# for sqrt(10**7) ~ 50%
for p in genprime():
    if p > 5000:
        break
    if p > 2000:
        primes.append(p)

print 'initial done'

primes.reverse()

res = []
for i in xrange(len(primes)):
    for j in xrange(i,len(primes)):
        p = primes[i]
        q = primes[j]
        if p*q > 10**7:
            continue
        if p!=q:
            phi = (p-1)*(q-1)
        else:
            phi = p*(p-1)
        if ispermutation(p*q,phi):
            res.append((float(p*q)/phi,p*q))
Ejemplo n.º 8
0
#! /usr/bin/env python

from eulerutils import genprime

gp = genprime()

for i in xrange(10001):
    p = gp.next()

print p