Chinaunix首页 | 论坛 | 博客
  • 博客访问: 86661
  • 博文数量: 47
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 625
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-11 12:11
文章分类

全部博文(47)

文章存档

2008年(47)

我的朋友

分类:

2008-11-15 23:15:40

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) |
0

上一篇:Problem 47

下一篇:problem 50

给主人留下些什么吧!~~