Problem 49
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another.
There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit increasing sequence.
What 12-digit number do you form by concatenating the three terms in this sequence?
公差为3330的三项等差序列1487、4817、8147在两个方面非常特别:其一,每一项都是素数;其二,两两都是重新排列的关系。
一位素数、两位素数和三位素数都无法构成满足这些性质的数列,但存在另一个由四位素数构成的递增序列也满足这些性质。
将这个数列的三项连接起来得到的12位数是多少?
def isprime(x):
if x <= 1:
return False
for i in range(2,int(x**0.5+1)):
if x % i == 0:
return False
return True
lst = []
for i in range(1000,10000):
if isprime(i):
lst.append(i)
lst2 = []
for x in lst:
for y in lst[lst.index(x)+1:]:
if 2*y-x in lst:
lst2.append([x,y,2*y-x])
for j in lst2:
if set(str(j[0]))==set(str(j[1]))==set(str(j[2])):
print(j)