Exemplo n.º 1
0
import importantFunctions as impf

primes = sorted(impf.generatePrimes(1000000))

maxx = 0
maxLen = 0
for i in range(len(primes)-1):
    rollingSum = primes[i]
    count = 1
    sumSet = [primes[i]]
    while rollingSum < primes[-1]:
        rollingSum+=primes[i+count]
        sumSet.append(primes[i+count])
        count+=1
        if impf.binarySearch(rollingSum, primes[i+count:])!= -1:
            if maxLen < len(sumSet):
                maxLen = len(sumSet)
                maxx = rollingSum
                print(maxx,len(sumSet))
                

Exemplo n.º 2
0
import time

def isPrime(n, primes):
    if math.sqrt(n) > primes[-1]:
        print("AHHHHHH BROKEN!!!!!!!!!!!!!")
        print(n)
        k = input()
        return True
    for p in primes:
        if p > math.sqrt(n):
            break
        if n%p == 0:
            return False
    return True
x = time.time()
primes = sorted(impf.generatePrimes(1000000))
i = 1
total = 1
spiralPrimes = []
while 1:
    a = [lambda x: 4*x**2-2*x+1, lambda x: 4*x**2+1, lambda x: 4*x**2+2*x+1]
    for j in range(3):
        n = a[j](i)
        if(isPrime(n, primes)):
            spiralPrimes.append(n)
    i += 1
    total+=4
    percent = len(spiralPrimes)/total*100
    #print(total, ":", percent)
    if percent < 10:
        break
Exemplo n.º 3
0
    for letter in lett:
        if s1.count(letter) != s2.count(letter):
            return False
    return True


def isArithmetic(lst):
    diff = abs(lst[1] - lst[0])
    for i in range(len(lst) - 1):
        if abs(lst[i + 1] - lst[i]) != diff:
            return False
    return True


x = time.time()
fdprimes = sorted(list(filter(lambda x: x > 1000, impf.generatePrimes(10000))))
perms = []
i = 0
for prime in fdprimes:
    perms.append([prime])
    for otherPrime in fdprimes:
        if isPerm(str(prime), str(otherPrime)):
            perms[i].append(otherPrime)
            fdprimes.remove(otherPrime)
    i += 1
perms = list(filter(lambda x: len(x) > 2, perms))
for lst in perms:
    for comb in itertools.combinations(lst, 3):
        if isArithmetic(list(comb)):
            print("".join([str(x) for x in comb]))
print(time.time() - x)
Exemplo n.º 4
0
9 = 7 + 2×1^2
15 = 7 + 2×2^2
21 = 3 + 2×3^2
25 = 7 + 2×3^2
27 = 19 + 2×2^2
33 = 31 + 2×1^2

It turns out that the conjecture was false.

What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?
#############################################################################################################################'''

import importantFunctions as impf

primes = impf.generatePrimes(10000)
primes.remove(2)
doubles = [2*(i**2) for i in range(0, 10000)]
odds = [1 for i in range(1, primes[-1], 2)]
odds[0] = 0
for prime in primes:
    for square in doubles:
        try:
            odds[int(((prime+square)-1)/2)]=0
        except IndexError:
            continue

for i in range(len(odds)):
    if odds[i]:
        print(2*i+1)
Exemplo n.º 5
0
    if s1 == s2:
        return False
    lett = set(list(s1))
    for letter in lett:
        if s1.count(letter) != s2.count(letter):
            return False
    return True

def isArithmetic(lst):
    diff = abs(lst[1]-lst[0])
    for i in range(len(lst)-1):
        if abs(lst[i+1]-lst[i])!=diff:
            return False
    return True
x = time.time()
fdprimes = sorted(list(filter(lambda x: x>1000, impf.generatePrimes(10000))))
perms = []
i = 0
for prime in fdprimes:
    perms.append([prime])
    for otherPrime in fdprimes:
        if isPerm(str(prime), str(otherPrime)):
            perms[i].append(otherPrime)
            fdprimes.remove(otherPrime)
    i+=1
perms = list(filter(lambda x: len(x)>2, perms))
for lst in perms:
    for comb in itertools.combinations(lst, 3):
        if isArithmetic(list(comb)):
            print("".join([str(x) for x in comb]))
print(time.time()-x)
Exemplo n.º 6
0
import importantFunctions as impf

def checkTruncPrime(x, lst):
    k = [i for i in str(x)]
    l = [i for i in str(x)]
    for i in range(len(k)-1):
        k.pop(0)
        l.pop()
        if (int("".join(k)) not in lst) or (int("".join(l)) not in lst):
            return False
    return True

limit = 1000000
primes = impf.generatePrimes(limit)
count = 0
tab = 0
for prime in primes:
    if checkTruncPrime(prime,primes):
        count += 1
        print(count-4, ":", prime)
        tab += prime
        if count == 15:
            print("Found them all")
            break
tab -= (2+3+5+7)
print("The sum of the ", count-4, "numbers I found is:", tab)