Problem 49
01 August 2003
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?
def fun49():
a = {}
result = []
for i in range(1,10):
for j in range(10):
for k in range(10):
for l in range(1, 10, 2):
num = i*1000+j*100+k*10+l
if num < 1000 and num > 3340:
break
if not isPrime(num):
continue
p = [i,j,k,l]
p.sort()
if a.has_key(str(p)):
continue
else:
a[str(p)] = 1
primes = set()
count = 0
for t in permutation(p, 4):
num = int("".join(map(str, t)))
if isPrime(num):
primes.add(num)
count += 1
if count >= 3:
for t in combination(list(primes), 3):
t.sort()
if (t[0] > 1000) and (2*t[1] == (t[0]+t[2])):
result.append([t, "".join(map(str, t))])
return result
answer is 296962999629, 三个数为2969, 6299, 9629
time:0.43799996376
阅读(464) | 评论(0) | 转发(0) |