Beispiel #1
0
import addmath

totient_memo = {}
print("Calculating primes...", end='')
primes = addmath.primes_under(1000000)
print("done.")

for prime in primes:
    totient_memo[prime] = prime - 1


def totient(n):
    if n in totient_memo:
        return totient_memo[n]
    i = 0
    prime = primes[i]
    acc = n
    while prime * prime <= n:
        prime = primes[i]
        if n % prime == 0:
            totient_memo[n] = totient(prime) * totient(n // prime)
            return totient_memo[n]
        i += 1
    if (n > 1):
        acc = acc * (1 - (1 / (n)))
    totient_memo[n] = int(acc)
    primes.append(n)
    return int(acc)


def is_permutation(n, k):
Beispiel #2
0
            ind = encountered.index(k)
            encountered = encountered[ind:]
            for item in encountered:
                chain_memo[item] = len(encountered)
            return 0
        encountered.append(k)
        length += 1
        k = next(k)
    encountered.append(n)
    for enc in encountered:
        chain_memo[enc] = length
    return length


limit = 1000000
primes = addmath.primes_under(limit)

loadMemo()

chain(14316)
print("Done.")
chain(next(14316))
#
# bestVal = 220
# bestLen = 2
# for i in range(1, limit):
#     k = chain(i)
#     print(i, bestVal, bestLen)
#     if k > bestLen:
#         bestVal = i
#         bestLen = k
Beispiel #3
0
import addmath

LIMIT = 1000000
primes = addmath.primes_under(LIMIT)


def sopf(n):
    i = 0
    tot = 0
    prime = primes[i]
    while prime <= n:
        if n % prime == 0:
            tot += prime
        i += 1
        prime = primes[i]
    return tot


kappa_memo = {}


def kappa(n):
    if n == 0:
        return 0
    if n in kappa_memo:
        return kappa_memo[n]
    acc = sopf(n)
    for j in range(1, n):
        acc += sopf(j) * kappa(n - j)
    acc = acc // n
    kappa_memo[n] = acc
Beispiel #4
0
import addmath


def quadratic(a, b, n):
    return (n**2) + (a * n) + b


primes = addmath.primes_under(87400)


def isPrime(n):
    i = 0
    while (primes[i] <= n):
        if (primes[i] == n):
            return True
        i += 1
    return False


print("produced primes")
aMax = bMax = nMax = 0
for a in range(-1000, 0):
    for b in range(-1000, 1000):
        n = 0
        while (isPrime(abs(quadratic(a, b, n)))):
            n += 1
        if (n > nMax):
            print("n2+" + str(a) + "n+" + str(b))
            nMax = n
            bMax = b
            aMax = a
Beispiel #5
0
import addmath
primes=set(addmath.primes_under(9999))

def is_permutation(n1, n2):
    n1=str(n1)
    n2=str(n2)
    if(len(n1)!=len(n2)):
        return False
    for c in n1:
        if c not in n2:
            return False
    return True

def sequence(n):
    cursor=n
    for increment in range(3330, 3331):
        if(cursor+increment in primes and cursor+(2*increment) in primes):
            if(is_permutation(cursor, cursor+increment) and is_permutation(cursor, cursor+(2*increment))):
                return (cursor, cursor+increment, cursor+2*increment)
    return False
    
def concat(n):
    return str(n[0])+str(n[1])+str(n[2])

for prime in primes:
    if(sequence(prime)!=False):
        print(concat(sequence(prime)))
Beispiel #6
0
import addmath
import numpy

primes = set(addmath.primes_under(2000000))


def truncatable(number):
    number = str(number)
    for i in range(len(number)):
        j = len(number) - i
        if (number[i:] == '' or number[:j] == ''):
            break
        if (not (int(number[i:]) in primes and int(number[:j]) in primes)):
            return False
    return True


trunc = []
sumall = 0
for i in primes:
    if (len(str(i)) == 1):
        continue
    if (truncatable(i)):
        trunc.append(i)

print(trunc)

for element in trunc:
    for digit in range(1, 10):
        new = str(element) + str(digit)
        if (truncatable(int(new)) and int(new) not in trunc):
Beispiel #7
0
import addmath

upperbound = int(input("Upperbound: "))
print(sum(addmath.primes_under(upperbound)))
Beispiel #8
0
import sys
sys.path.append('../libraries')
import addmath


def pandigital(number, n):
    number_set = addmath.get_digits(number)
    if (len(number_set) != len(str(number)) or 0 in number_set):
        return False
    for i in range(1, n):
        if i not in number_set:
            return False
    return True


primes = addmath.primes_under(7654321)
for i in range(len(primes) - 1, -1, -1):
    if (pandigital(primes[i], 7)):
        print(primes[i])
        break