예제 #1
0
def solve():
    total = 0

    # Filter out any primes that contain even numbers, as at least one rotation
    # will be divisible by 2
    prime_list = set(filter(lambda i: not set(str(i)).difference(["1", "3", "5", "7", "9"]),
                            sieve_of_atkin(10 ** 6)))

    for prime in prime_list:
        if are_rotations_prime(prime, prime_list):
            total += 1

    # +1 for 2, because it was excluded while removing numbers containing
    # even digits
    return total + 1
예제 #2
0
def solve():
    longest_seq = 0
    max_coefficients = (0, 0)
    prime_list = sieve_of_atkin(87400)

    # The range in which the condition |a| < 1000 is true
    for a in range(-999, 0, 2):
        # The range in which the condition |b| < 1000 is true
        for b in range(-a, 1000, 2):
            n = 1
            while is_prime(n * (n + a) + b, prime_list):
                n += 1

            if n > longest_seq:
                longest_seq = n
                max_coefficients = (a, b)

    return max_coefficients[0] * max_coefficients[1]
def solve():
    def is_twice_square(n):
        return sqrt(n / 2).is_integer()

    answer = 1
    found = False

    primes = sieve_of_atkin(10000)

    while not found:
        index = 0
        found = True
        answer += 2

        while answer >= primes[index]:
            if is_twice_square(answer - primes[index]):
                found = False
                break

            index += 1

    return answer
예제 #4
0
def solve():
    return sieve_of_atkin(105000)[10000]
예제 #5
0
def longest_cycle(ceiling):
    # Only bother testing prime numbers, as they produce recurring cycles
    return max(primes.sieve_of_atkin(ceiling), key=lambda n: len_recurring_cycle(n))