Ejemplo n.º 1
0
def main():
    power_list = euler.prime_list_with_zeros(LIMIT1)
    fast_list = power_list[:]
    max_divisors = euler.max_divisors(range(LIMIT1))
    total = 0
    for i in range(len(power_list) - 1, -1, -1):
        if power_list[i]:
            temp = i
            while temp < LIMIT1:
                power_list[temp] = 1
                temp *= i
    for n in range(2, LIMIT1):
        if power_list[n]:
            total += 1
        elif not n & 1 and fast_list[n >> 1]:
            total += (n >> 1) + 1
        else:
            max_divisor = max_divisors[n]
            r = n // max_divisor
            for a in range(r - 1, 0, -1):
                a_m = a * max_divisor
                if not a_m * (a_m + 1) % n:
                    total += a_m + 1
                    break
                if not a_m * (a_m - 1) % n:
                    total += a_m
                    break
    return total
Ejemplo n.º 2
0
def main():
    lst = euler.prime_list_with_zeros(LIMIT)
    count = 0
    for n in lst:
        if n:
            for rounding in get_round(n):
                if lst[rounding] == 0:
                    break
            else:
                count += 1
    return count
Ejemplo n.º 3
0
def main():
    lst = euler.prime_list_with_zeros(LIMIT**2)
    double_squares = [2 * i**2 for i in range(1, LIMIT + 1)]
    number = 33
    while True:
        number += 2
        if lst[number] == 0:
            for i in range(LIMIT):
                must_be_prime = number - double_squares[i]
                if must_be_prime > 0:
                    if lst[must_be_prime] != 0:
                        break
                else:
                    return number
Ejemplo n.º 4
0
def main():
    lst = euler.prime_list_with_zeros(LIMIT)
    prime_list = [n for n in lst if n != 0]
    length = len(prime_list)
    prime = 0
    max_j = 0
    for i in range(length):
        for j in range(1, length - i):
            total = sum(prime_list[i:i + j])
            if total > 1000000:
                if j < max_j:
                    return prime
                break
            if lst[total] != 0:
                prime = max(prime, total)
                max_j = max(max_j, j)
    return prime
Ejemplo n.º 5
0
def main():
    lst = euler.prime_list_with_zeros(LIMIT)
    total = 0
    for i in range(10, LIMIT):
        if lst[i] != 0:
            ind = i
            while ind > 10:
                ind = ind // 10
                if lst[ind] == 0:
                    break
            else:
                ind = i
                while ind > 10:
                    ind = ind % 10**int(math.log(ind, 10))
                    if lst[ind] == 0:
                        break
                else:
                    total += i
    return total
Ejemplo n.º 6
0
def main():
    primes_for_square = euler.prime_list_with_zeros(int(LIMIT ** 0.5))
    primes_for_cube = euler.clean_zeros(
        primes_for_square[:int(LIMIT ** (1 / 3))]
    )
    primes_for_forth_power = euler.clean_zeros(
        primes_for_square[:int(LIMIT ** 0.25)]
    )
    primes_for_square = euler.clean_zeros(primes_for_square)
    numbers = set()
    for i in primes_for_forth_power:
        for j in primes_for_cube:
            temp = i ** 4 + j ** 3
            if temp >= LIMIT:
                break
            for k in primes_for_square:
                n = temp + k ** 2
                if n < LIMIT:
                    numbers.add(n)
    return len(numbers)
Ejemplo n.º 7
0
def main():
    lst = euler.prime_list_with_zeros(10000)
    for i in range(1000, 10000):
        if (
                lst[i] != 0 and
                lst[i] != 1487
        ):
            for diff in range(500, (10000 - i) // 2):
                if (
                        lst[i + diff] != 0 and
                        lst[i + 2 * diff] != 0 and
                        (
                            set(str(lst[i])) ==
                            set(str(lst[i + diff])) ==
                            set(str(lst[i + 2 * diff]))
                        )
                ):
                    return int(
                        str(lst[i]) +
                        str(lst[i + diff]) +
                        str(lst[i + 2 * diff])
                    )
    return 0
Ejemplo n.º 8
0
import itertools

import euler

ANSWER = 71
LIMIT = 5000

PRIME_LIST_WITH_ZEROS = euler.prime_list_with_zeros(LIMIT)
PRIME_LIST = euler.clean_zeros(PRIME_LIST_WITH_ZEROS)


def sum_two(n, index):
    result = 0
    prime = PRIME_LIST[index]
    n_2 = n // 2
    while prime <= n_2:
        if PRIME_LIST_WITH_ZEROS[n - prime]:
            result += 1
        index += 1
        prime = PRIME_LIST[index]
    return result


def sum_count(n, count, index=0):
    if n < count * 2:
        return 0
    if count == 2:
        return sum_two(n, index)
    prime = PRIME_LIST[index]
    smallest = n // count
    result = 0
Ejemplo n.º 9
0
import euler

ANSWER = 1739023853137
LIMIT = 10**8
LIMIT2 = LIMIT + 2
PRIME_LIST = euler.prime_list_with_zeros(LIMIT2)


def check(n):
    sqrt = int(n**0.5) + 1
    for i in range(3, sqrt):
        if not n % i:
            if not PRIME_LIST[i + n // i]:
                return False
    return True


def main():
    total = 1
    for i in range(2, LIMIT // 2 + 3):
        q = 2 * i - 4
        if PRIME_LIST[i]:
            if PRIME_LIST[q + 1]:
                if check(q):
                    total += q
    return total


if __name__ == '__main__':
    print(main())