2013-04-17 14:34:39 +08:00

58 lines
953 B
Python

from string import maketrans, translate
def numbreak(x):
out = []
while x != 0:
out.append(x % 10)
x /= 10
return set(out)
def numloop(x, a, lis):
out = []
for i in xrange(10 - a):
tt = maketrans(str(a), str(i + a))
tmp = int(translate(str(x), tt))
if isp(tmp, lis):
out.append(tmp)
return out
def isp(x, lis):
for i in lis:
if x % i == 0:
return False
if x < i ** 2:
break
return True
def makeP(x):
p = [2]
P = [2]
n = 3
while n < x:
for i in p:
if n % i == 0:
break
else:
P.append(n)
n += 2
while n > p[-1] ** 2:
p.append(P[len(p)])
return P
prime = makeP(100000)
def main():
xx = 56003
while 1:
ss = numbreak(xx)
for syn in xrange(3):
if syn in ss:
tmp = numloop(xx, syn, prime)
if len(tmp) >= 8:
print xx, tmp
return
xx += 2
while not isp(xx, prime): xx += 2
main()