Exemplo n.º 1
0
def S(N):
    primes = soe(N//2+10)#[-1::-1]
    s = 0
    tmp = 0
    tmp2 = 0
    tmpp = 0
    mini = 0
    count = False
    for p,q in combinations(primes,2):
        #if p>3162:break
        if p==tmpp:continue
        if p*q>N:
            if count and p!=tmpp:
                #break
                pass
            else:
                tmpp = p
                count = True
                continue
        else:
            count = False
            tmpp=0
        if tmp2!=p:
            mini=0
            tmp2=p
        if q>mini:
            mini+=3000
            #print(p,q,end='\r')
        t = M(p,q,N)
        if t==0:
            return s
        else:
            print(t)
        s+=t
    return s
Exemplo n.º 2
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.º 3
0
def test(num,n):
    p = soe(n+1)+[0]
    j = 0
    while p[j]!=0:
        if num%p[j]==0:
            num=num//p[j]
        else:
            j+=1
    if num<n:
        return True
    else:
        return False
Exemplo n.º 4
0
def isprime3(num, primes = [2,3,5,7,11,13,17,19]):
    if len(primes)==0:primes = [2,3,5,7,11,13,17,19]
    if num<=primes[-1]:
    	 if num in primes:return True
    	 else:return False
    for i in primes:
    	 if num%i==0:return False
    if num**.5<primes[-1]:return True
    else:
    	 p = soe(int(num**.5)-1)
    	 if p[-1]==primes[-1]:return True
    	 return isprime3(num,p)
Exemplo n.º 5
0
def e134():
    top = 10**6
    bot = 5
    tot = 0
    primes = soe(top+1)
    primes = primes[primes.index(bot):]
    mini = 100;
    for i, num in enumerate(primes):
        if i>mini:
            print(i/len(primes))
            mini+=100
        if i==len(primes)-1:
            break
        tot += findnum(num, primes[i+1])
    return tot
Exemplo n.º 6
0
def Euler_87():
    prime1 = soe(maxp)
    count = set()
    x = 1
    last = 0
    for i in soegen(90):
        tmp =i**4
        if tmp>=top:break
        print(i)
        for j in soegen(400):
            tmp=j**3+i**4
            if tmp>=top:break
            for k in soegen(8000):
                tmp = k**2+j**3+i**4
                if tmp == top:print('wtf')
                if tmp<top:
                    count.add(tmp)
                else:break
    return len(count)
    '''
Exemplo n.º 7
0
from script.allsieve import primesfrom2to,soe
a = soe(10**7)
Exemplo n.º 8
0
    Considering quadratics of the form:

    n² + an + b, where |a| < 1000 and |b| < 1000

    where |n| is the modulus/absolute value of n
    e.g. |11| = 11 and |4| = 4
    Find the product of the coefficients, a and b, for the quadratic expression
    that produces the maximum number of primes for consecutive values of n,
    starting with n = 0.
'''
#primes = maths.primesd(100000)
from script.allsieve import soe
#from script.isprime import isprime
from script.maths import isprime2 as isprime
primes = dict.fromkeys(soe(10**5),1)
def Euler_27(numa=1000,numb=1000):
    big = 0
    for a in range(-numa,numa):
        print(a/1000,end='\r')
        for b in range(-numb,numb):
            n = 0
            val = n**2+n*a+b
            if isprime(val):
                num = 0
                while isprime(val):
                    num+=1
                    n+=1
                    val = n**2+n*a+b
                if big<n:
                    big = n
Exemplo n.º 9
0
def e123(top=pow(10,10)): 
    p = soe(10**6)
    for n in range(len(p)):
        if ((2*(n+1)*p[n])%(p[n]*p[n]) > top and n%2 == 0):
            return n+1
Exemplo n.º 10
0
from script.maths import primesd
from script.allsieve import soe
from math import sqrt
primes = soe(10**6)
pd = dict.fromkeys(primes,1)
nprime = [x for x in range(1,10**6,2) if not pd.get(x)] 
def Euler_46():
    b = True
    t = False
    print('start')
    for check in nprime[2:]:
        for i in primes:
            if i>check:return check
            for j in range(1,(check-i)):
                if 2*j**2>(check-i+2):break
                if i+2*(j**2)==check:t = True;break
            if t:t = False;break
if __name__=='__main__':
    print(Euler_46())

Exemplo n.º 11
0
from script.maths import primesd
from script.allsieve import soe
from math import sqrt
primes = soe(10**6)
pd = dict.fromkeys(primes, 1)
nprime = [x for x in range(1, 10**6, 2) if not pd.get(x)]


def Euler_46():
    b = True
    t = False
    print('start')
    for check in nprime[2:]:
        for i in primes:
            if i > check: return check
            for j in range(1, (check - i)):
                if 2 * j**2 > (check - i + 2): break
                if i + 2 * (j**2) == check:
                    t = True
                    break
            if t:
                t = False
                break


if __name__ == '__main__':
    print(Euler_46())