Exemplo n.º 1
0
def Euler_41():
    high = [0]
    for i in range(1,8):
  #      primes = [str(x) for x in maths.primes(10**(i)//4,10**(i-1)//4)]
        alist =["".join(x) for x in  itertools.permutations("".join([str(x) for x in range(1,i+1)]))]
        high=[x for x in alist if maths.isprime2(int(x))]
    return high[-1]
Exemplo n.º 2
0
def e146(top=10 ** 6):
    ret = 0
    x1 = lambda n: n ** 2 + 1
    x2 = lambda n: n ** 2 + 3
    x3 = lambda n: n ** 2 + 7
    x4 = lambda n: n ** 2 + 9
    x5 = lambda n: n ** 2 + 13
    x6 = lambda n: n ** 2 + 27
    test = [x1, x2, x3, x4, x5, x6]
    mini = 1000
    for i in range(1, top + 1):
        if i > mini:
            print(i)
            mini += 1000
        z = 0
        yesno = i
        for j in test:
            y = j(i)
            if z:
                if y != z:
                    yesno = 0
                    break
            if not isprime2(y):
                continue
            z = nextprime(y)
        ret += yesno
    return ret
Exemplo n.º 3
0
def e146(top=10**6):
    ret = 0
    x1 = lambda n: n**2 + 1
    x2 = lambda n: n**2 + 3
    x3 = lambda n: n**2 + 7
    x4 = lambda n: n**2 + 9
    x5 = lambda n: n**2 + 13
    x6 = lambda n: n**2 + 27
    test = [x1, x2, x3, x4, x5, x6]
    mini = 1000
    for i in range(1, top + 1):
        if i > mini:
            print(i)
            mini += 1000
        z = 0
        yesno = i
        for j in test:
            y = j(i)
            if z:
                if y != z:
                    yesno = 0
                    break
            if not isprime2(y): continue
            z = nextprime(y)
        ret += yesno
    return ret
Exemplo n.º 4
0
def Euler_5(top=20):
    val = 1
    for i in range(1,top+1):
        if maths.isprime2(i):
            num = i
            while num<=top:
                num = num*i
            val *=(num//i)
    return val
Exemplo n.º 5
0
def e131(top=10**6):
    i = 1
    j = 2
    count = 0
    while True:
        p = j**3 - i**3
        if p >= top: break
        if isprime2(p): count += 1
        i, j = j, j + 1
    return count
Exemplo n.º 6
0
def e131(top = 10**6):
    i = 1
    j = 2
    count = 0
    while True:
        p = j**3-i**3
        if p>=top:break
        if isprime2(p):count+=1
        i,j = j,j+1
    return count
Exemplo n.º 7
0
def factors(x,i=0):
    if isprime2(x):return [x]
    p = sieve(int(x**.5))
    for j,prime in enumerate(p[i:]):
        tmp = x%prime
        if tmp==0:
            tp = x//prime
            print(tmp,prime)
            return [prime]+factors(tp,j)
    return [x]
Exemplo n.º 8
0
def Euler_3(num=600851475143):
    primes = []
    i = 2
    while i <= num:
        if num % i == 0 and isprime2(i):
            num = num // i
            primes = primes + [i]
            i = 2
        i += 1
    return max(primes)
Exemplo n.º 9
0
def Euler_41():
    high = [0]
    for i in range(1, 8):
        #      primes = [str(x) for x in maths.primes(10**(i)//4,10**(i-1)//4)]
        alist = [
            "".join(x) for x in itertools.permutations("".join(
                [str(x) for x in range(1, i + 1)]))
        ]
        high = [x for x in alist if maths.isprime2(int(x))]
    return high[-1]
Exemplo n.º 10
0
def Euler_3(num=600851475143):
    primes = []
    i=2
    while i <= num:
        if num%i ==0 and isprime2(i):
            num = num//i
            primes = primes +[i] 
            i = 2
        i+=1
    return max(primes)
Exemplo n.º 11
0
def factors(x, i=0):
    if isprime2(x): return [x]
    p = sieve(int(x**.5))
    for j, prime in enumerate(p[i:]):
        tmp = x % prime
        if tmp == 0:
            tp = x // prime
            print(tmp, prime)
            return [prime] + factors(tp, j)
    return [x]
Exemplo n.º 12
0
def factors(n):
    global primes
    p = primes
    if n ==1:return [1]
    if n in p:return [n]
    else:
        for i in range(len(p)):
            if n%p[i]==0:
                result =[p[i]]+factors(n//p[i])#,primes)
                return result
    if isprime2(n):return [n]
    else: 
        primes+=[nextprime(primes[-1])]
        return factors(n)#,primes)
Exemplo n.º 13
0
def factors(n):
    global primes
    p = primes
    if n == 1:
        return [1]
    if n in p:
        return [n]
    else:
        for i in range(len(p)):
            if n % p[i] == 0:
                result = [p[i]] + factors(n // p[i])  # ,primes)
                return result
    if isprime2(n):
        return [n]
    else:
        primes += [nextprime(primes[-1])]
        return factors(n)  # ,primes)
Exemplo n.º 14
0
def nextprime(p):
    if p%2==0:p+=1
    while not isprime2(p):
        p+=2
    if p>=top:return []
    return [p]+nextprime(p+1)
Exemplo n.º 15
0
def nextprime(p):
    if p % 2 == 0: p += 1
    while not isprime2(p):
        p += 2
    if p >= top: return []
    return [p] + nextprime(p + 1)