Ejemplo n.º 1
0
def tester(n):
    def _key(z):
        return z[1][1]  #len(z[1])

    euler_tools.write_primes(int(n))
    primes = euler_tools.read_primes()
    with euler_tools.Watch():
        print(prime_divisor(9917, primes))
Ejemplo n.º 2
0
import euler_tools

euler_tools.write_primes(12001)
PRIMES = sorted(euler_tools.read_primes())

def gcd(a, b):
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
    return b

def coprime_2(n, m):
    return gcd(n, m) == 1

def totients(n):
    t = list(range(1, n+1))
    for p in PRIMES:

        m = 1
        while m*p <= n:
            t[m*p-1] *= (1-1/p)
            m += 1

    return [int(_t) for _t in t]

CP = {}

def coprime(n, m):
    try:
Ejemplo n.º 3
0
#tester(1e6)

#euler_tools.write_primes(D)

#with euler_tools.Watch():
#print(euler_tools.prime_divisors(12345678))

#euler_tools.write_primes(int(1e6))

#with euler_tools.Watch():
#    print(euler_tools.prime_divisors(12345678))

D = int(1e6) + 1

euler_tools.write_primes(int(1e6))
primes = euler_tools.read_primes()

#with euler_tools.Watch():
#    x = [euler_tools.totient(i, primes) for i in range(2, D)]

#print(x)
#print(sum(x))

lst = list(range(D))
for p in primes:
    r = p - 1
    lst[p] = r
    lst[p + p::p] = [i / p * (p - 1) for i in lst[p + p::p]]

print(sum(lst[2:]))
Ejemplo n.º 4
0
import decimal
import euler_tools

euler_tools.write_primes(int(1e5))
PRIMES = euler_tools.read_primes()


def ppt(n):
    def powers(k):
        _powers = []
        for p in PRIMES:
            num = p**k
            if num < n:
                _powers.append(num)
            else:
                break
        return _powers

    squares = powers(2)
    cubes = powers(3)
    tesseracts = powers(4)

    ppts = []
    for square in squares:
        for cube in cubes:
            for tesseract in tesseracts:
                x = square + cube + tesseract
                if x < n:
                    ppts.append(x)

    return set(ppts)