Exemplo n.º 1
0
def first_over(count, max_prime):
    primes = sieve(max_prime)
    i = 2
    while count_sums(i, 0,
                     sorted(filter(lambda x: x <= i, primes))[::-1]) <= count:
        i += 1
    return i
Exemplo n.º 2
0
def least_totient(max_):
    primes = sieve(max_)
    best_n = 0
    best_tot = 1
    for n in range(2,max_):
        if n in primes:
            continue
        tot = totient(n,primes)
        if n / tot > best_n / best_tot:
            best_n = n
            best_tot = tot
    return best_n
Exemplo n.º 3
0
def num_proper_fractions_2(max_):
    primes = sieve(max_)
    total = max_-1
    for i in range(2,max_):
        cur = 0
        if i in primes:
            total += (max_-i)-((max_-i)//i)
        else:
            if len(pf := prime_factors(i)) == 1:
                total += (max_-i)-((max_-i)//next(iter(pf)))
            else:
                total += range_totient(i,min_=i,max_=max_,factors=pf)
Exemplo n.º 4
0
def num_sums_below(sum_bound, prime_bound):

    primes = sieve(prime_bound)
    primes_2 = set(filter(lambda x: x <= sum_bound**(1 / 2), primes))
    primes_3 = set(filter(lambda x: x <= sum_bound**(1 / 3), primes))
    primes_4 = set(filter(lambda x: x <= sum_bound**(1 / 4), primes))

    found = set()
    for square in primes_2:
        for cube in primes_3:
            for quad in primes_4:
                if (sum_ := square**2 + cube**3 + quad**4) < sum_bound:
                    found.add(sum_)
Exemplo n.º 5
0
def least_totient_perm(max_):
    primes = sieve(max_)
    best_n = max_ + 1
    best_tot = 1
    for n in range(2, max_):
        if n % 500000 == 0:
            print(n)
        if n in primes:
            found[n] = n - 1
            continue
        tot = totient(n, primes)
        if n / tot < best_n / best_tot:
            if is_permutation(n, tot):
                best_n = n
                best_tot = tot
    return best_n