Exemplo n.º 1
0
def e007(n=10001):
    x = 3
    i = 2
    while i < n:
        if isprime(x):
            i += 1
        x += 2
    return x - 2
    '''
Exemplo n.º 2
0
def e007(n=10001):
    x = 3
    i=2
    while i<n:
        if isprime(x):
            i+=1
        x+=2
    return x-2
    '''
Exemplo n.º 3
0
def Euler_7(n = 10001):
    p = primesd3(10**6)
    print()
    return p[n-1]
    i =1 
    num = 0;
    while i<n:
        num +=1
        if isprime(num):
            i +=1
    return num 
Exemplo n.º 4
0
def Euler_7(n=10001):
    p = primesd3(10**6)
    print()
    return p[n - 1]
    i = 1
    num = 0
    while i < n:
        num += 1
        if isprime(num):
            i += 1
    return num
Exemplo n.º 5
0
def N(n,d):
    count = 0
    nums = []
    m = M(n,d)
    s = '0123456789'
    for j in product(s,repeat = n):
        i = int(''.join(j))
        if len(str(i))==n:
            if not isprime(i):continue
            if str(i).count(str(d))==m:
                count+=1
                nums+=[i]
    return [count,nums]
Exemplo n.º 6
0
def Euler_35(num=10**6):
    i = 0
    for x in soegen(num):
        b = True
        y = str(x)
        if evendig(y):continue
        yn = rotatestr(y)
        while yn!=y:
            b = isprime(int(yn))
            if not b:break
            yn = rotatestr(yn)
        if b:
            i+=1
    return i
Exemplo n.º 7
0
def Euler_35(num=10**6):
    i = 0
    for x in soegen(num):
        b = True
        y = str(x)
        if evendig(y): continue
        yn = rotatestr(y)
        while yn != y:
            b = isprime(int(yn))
            if not b: break
            yn = rotatestr(yn)
        if b:
            i += 1
    return i
Exemplo n.º 8
0
def M(n,d):
    s = '0123456789'
    maxn = 0
    d = str(d)
    mini = 1000
    for i in product(s,repeat = n): 
        j = ''.join(i)
        if j[0]=='0':continue
        c = j.count(d)
        if d=='0' and c==n-2:return c
        if c>maxn:
            if isprime(int(j)):
                maxn=c
        if maxn==n-1:
            return maxn
    return maxn
    '''
Exemplo n.º 9
0
def e060():
    x = soe(10**4)
    print('{:>4}'.format('start'))
    for i in x:
        print(str(i))
        p1 = sorted(set(j for j in soe(10**4) if j>i and \
            isprime(str(j)+str(i)) and isprime(str(i)+str(j))))
        for j in p1:
            p2 = sorted(set(k for k in p1 if k>j and \
                isprime(str(j)+str(k)) and isprime(str(k)+str(j))))
            for k in p2:
                p3 = sorted(set(l for l in p2 if l>k and \
                    isprime(str(k)+str(l)) and isprime(str(l)+str(k))))
                for l in p3:
                    p4 = sorted(set(m for m in p3 if m>l and \
                        isprime(str(m)+str(l)) and isprime(str(l)+str(m))))
                    if len(p4):
                        print( [i,j,k,l,p4[0],[i+j+k+l+p4[0]]])
                        return 1
Exemplo n.º 10
0
def e060():
    x = soe(10**4)
    print('{:>4}'.format('start'))
    for i in x:
        print(str(i))
        p1 = sorted(set(j for j in soe(10**4) if j>i and \
            isprime(str(j)+str(i)) and isprime(str(i)+str(j))))
        for j in p1:
            p2 = sorted(set(k for k in p1 if k>j and \
                isprime(str(j)+str(k)) and isprime(str(k)+str(j))))
            for k in p2:
                p3 = sorted(set(l for l in p2 if l>k and \
                    isprime(str(k)+str(l)) and isprime(str(l)+str(k))))
                for l in p3:
                    p4 = sorted(set(m for m in p3 if m>l and \
                        isprime(str(m)+str(l)) and isprime(str(l)+str(m))))
                    if len(p4):
                        print([i, j, k, l, p4[0], [i + j + k + l + p4[0]]])
                        return 1
Exemplo n.º 11
0
def solve():
    p = 1
    while True:
        p = nextprime(p)
        digs = digits(p)
        numdigs = len(digs)
        uniquedigs = list(set(digs))
        uniquedigs.sort()
        indexes = [None] * 10
        for i in range(numdigs):
            d = digs[i]
            if indexes[d] is None:
                indexes[d] = []
            indexes[d].append(i)
        for d in uniquedigs:
            # The first member of a family have recurring digits,
            # each of which is one of 0, 1, and 2.
            if d > 2:
                continue
            inds = indexes[d]
            # If the number of recurring digits is not a multiple of 3 or
            # one of the digits is the least significant, then the family
            # can't have 8 members.
            if len(inds) % 3 == 0 and inds[-1] != numdigs - 1:
                start = 1 if inds[0] == 0 else 0
                numgenerated = 10 - start
                numprimes = 0
                numcomposites = 0
                # Generate family candidates
                for e in range(start, 10):
                    for i in inds:
                        digs[i] = e
                    number = digits_to_number(digs)
                    if isprime(number):
                        numprimes += 1
                    else:
                        numcomposites += 1
                    if numcomposites > numgenerated - 8:
                        break
                if numprimes == 8:
                    return p
Exemplo n.º 12
0
def solve():
    p = 1
    while True:
        p = nextprime(p)
        digs = digits(p)
        numdigs = len(digs)
        uniquedigs = list(set(digs))
        uniquedigs.sort()
        indexes = [None] * 10
        for i in range(numdigs):
            d = digs[i]
            if indexes[d] is None:
                indexes[d] = []
            indexes[d].append(i)
        for d in uniquedigs:
            # The first member of a family have recurring digits,
            # each of which is one of 0, 1, and 2.
            if d > 2:
                continue
            inds = indexes[d]
            # If the number of recurring digits is not a multiple of 3 or
            # one of the digits is the least significant, then the family
            # can't have 8 members.
            if len(inds) % 3 == 0 and inds[-1] != numdigs - 1:
                start = 1 if inds[0] == 0 else 0
                numgenerated = 10 - start
                numprimes = 0
                numcomposites = 0
                # Generate family candidates
                for e in range(start, 10):
                    for i in inds:
                        digs[i] = e
                    number = digits_to_number(digs)
                    if isprime(number):
                        numprimes += 1
                    else:
                        numcomposites += 1
                    if numcomposites > numgenerated - 8:
                        break
                if numprimes == 8:
                    return p
Exemplo n.º 13
0
from script.primes import isPrime as ip
#from script.maths import isprime2
from script.isprime import isprime
from time import time
from script.maths import nextprime
from script.prime import is_prime
x = 1000
t = time()
for i in range(1,x):
    a = ip(i)
print(time()-t)
'''
t = time()
for i in range(1,x):
    a = isprime2(i)
print(time()-t)
'''
t = time()
for i in range(1,x):
    a = isprime(i)
print(time()-t)
for i in range(1,x):
    a = is_prime(i)
print(time()-t)