30 lines
802 B
Python
30 lines
802 B
Python
|
|
from tools import number_theory
|
|
|
|
def trans_num(num):
|
|
s_num = str(num)
|
|
digit = set(s_num)
|
|
digit.remove(s_num[-1])
|
|
for d in digit:
|
|
if d == s_num[0]:
|
|
yield [int(s_num.replace(d, ch)) for ch in '123456789' if ch != d]
|
|
else:
|
|
yield [int(s_num.replace(d, ch)) for ch in '0123456789' if ch != d]
|
|
|
|
def is_prime(num):
|
|
for p in range(3, int(num ** 0.5) + 1):
|
|
if not num % p:
|
|
return False
|
|
return True
|
|
|
|
def search(limit, count):
|
|
prime = list(filter(lambda x: x > 100000, number_theory.make_prime(limit)))
|
|
while len(prime):
|
|
p = prime.pop(0)
|
|
for l in trans_num(p):
|
|
pl = list(filter(is_prime, l))
|
|
if count - 1 <= len(pl):
|
|
return [p] + pl
|
|
|
|
print(min(search(200000, 8)))
|