Exemplo n.º 1
0
from prime import get_is_prime_array

is_prime = get_is_prime_array(99999)


def check_pattern(pattern):
    step = int("".join(map(lambda c: "1" if c == "*" else "0", pattern)))
    initial_digit = 1 if pattern[0] == "*" else 0
    stop_multiplier = 10 - initial_digit
    start = int(pattern.replace("*", str(initial_digit)))
    smallest = None
    count = 0
    for multiplier in range(0, stop_multiplier):
        generated_number = start + multiplier * step
        if is_prime[generated_number]:
            if smallest == None:
                smallest = generated_number
            count += 1
    return smallest, count


print(check_pattern("*3"))
print(check_pattern("56**3"))
Exemplo n.º 2
0
from prime import get_is_prime_array

till = 2000000
is_prime = get_is_prime_array(till - 1)
result = sum(n for n in range(1, till) if is_prime[n])
print(result)
Exemplo n.º 3
0
import prime


def get_truncations(n):
    yield n
    d = 10
    while d <= n:
        yield n % d
        yield n // d
        d *= 10


till = 1000000
is_prime = prime.get_is_prime_array(till)
result = sum(n for n in range(11, till, 2)
             if all(is_prime[m] for m in get_truncations(n)))
print(result)
Exemplo n.º 4
0
# 'Simple' solution because based on the assumption that the terms have to increase by exact 3330, see also the discussion on https://www.mathblog.dk/project-euler-49-arithmetic-sequences-primes-permutations/
from prime import get_is_prime_array

step = 3330
till = 10000
is_prime_array = get_is_prime_array(till)

for i in range(1001, till - 2 * step, 2):
	if is_prime_array[i] and is_prime_array[i+step] and is_prime_array[i+2*step]:
		if sorted(str(i)) == sorted(str(i+step)) == sorted(str(i+2*step)):
			if i != 1487:
				print(str(i) + str(i+step) + str(i+2*step))