欧拉计划 61 题

原创 2015年07月07日 09:38:52

Triangle, square, pentagonal, hexagonal, heptagonal, and octagonal numbers are all figurate (polygonal) numbers and are generated by the following formulae:

Triangle   P3,n=n(n+1)/2   1, 3, 6, 10, 15, ...
Square   P4,n=n2   1, 4, 9, 16, 25, ...
Pentagonal   P5,n=n(3n1)/2   1, 5, 12, 22, 35, ...
Hexagonal   P6,n=n(2n1)   1, 6, 15, 28, 45, ...
Heptagonal   P7,n=n(5n3)/2   1, 7, 18, 34, 55, ...
Octagonal   P8,n=n(3n2)   1, 8, 21, 40, 65, ...

The ordered set of three 4-digit numbers: 8128, 2882, 8281, has three interesting properties.

  1. The set is cyclic, in that the last two digits of each number is the first two digits of the next number (including the last number with the first).
  2. Each polygonal type: triangle (P3,127=8128), square (P4,91=8281), and pentagonal (P5,44=2882), is represented by a different number in the set.
  3. This is the only set of 4-digit numbers with this property.

Find the sum of the only ordered set of six cyclic 4-digit numbers for which each polygonal type: triangle, square, pentagonal, hexagonal, heptagonal, and octagonal, is represented by a different number in the set.



import itertools
def triangle(u):
    for i in xrange(1,200):        
        u.append(i*(i+1)/2)
        
u=[]
triangle(u)

def square(u):
     for i in xrange(1,200):        
        u.append(i**2)
u1 =[]
square(u1)

def pentagonal(u):
     for i in xrange(1,200):        
        u.append(i*(3*i-1)/2)
u2 =[]
pentagonal(u2)

def hexagonal(u):
     for i in xrange(1,200):        
        u.append(i*(2*i-1))
        
u3 = []
hexagonal(u3)

def heptagonal(u):
     for i in xrange(1,200):        
        u.append(i*(5*i-3)/2)
u4 = []
heptagonal(u4)

def octagonal(u):
     for i in xrange(1,200):        
        u.append(i*(3*i-2))
u5 = []
octagonal(u5)


def finde4(u):
    d=[]
    for i in xrange(1,199):
        if u[i]<10000 and u[i]>999:
            d.append(u[i])
    return d
        
a1 = finde4(u)
a2 = finde4(u1)
a3 = finde4(u2)
a4 = finde4(u3)
a5 = finde4(u4)
a6 = finde4(u5)
 
pList = [a1,a2,a3,a4,a5,a6]

for p in itertools.permutations(range(5,-1,-1), 6):
        for t1 in pList[p[0]]:
            for t2 in pList[p[1]]:
                if t2/100 != t1%100:
                    continue
                for t3 in pList[p[2]]:
                    if t3/100 != t2%100:
                        continue
                    for t4 in pList[p[3]]:
                        if t4/100 != t3%100:
                            continue
                        for t5 in pList[p[4]]:
                            if t5/100 != t4%100:
                                continue
                            for t6 in pList[p[5]]:
                                if t6/100 == t5%100 and t6%100 == t1/100:
                                    print t1,t2,t3,t4,t5,t6
                                else:
                                    continue




版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

欧拉计划 61

三角形数,四角形数,五角形数,六角形数,七角形数和八角形数都是定形数,他们分别由以下公式产生:三角形数 P3,n=n(n+1)/2 1, 3, 6, 10, 15, … 四...

欧拉计划1-50题

  • 2012-03-27 21:09
  • 112KB
  • 下载

欧拉计划1-50题中文

  • 2013-10-05 15:14
  • 73KB
  • 下载

欧拉计划 第4题

题目 A palindromic number reads the same both ways. The largest palindrome made from the product of ...

欧拉计划网第二十三题解决方案

题目23:算出所有不能写成两个过剩数之和的正整数之和。 如果一个数的所有真因子之和等于这个数,那么这个数被称为完全数。例如,28的所有真因子之和为1 + 2 + 4 + 7 + 14 = 28,所...

欧拉计划网第十三题解决方案

题目13:找出100个50位数之和的前十位数字。 找出以下100个50位数之和的前十位数字。 3710728753390210279879799822083759024651...

欧拉计划第5题

Problem 5:         2520 is the smallest number that can be divided...

Project Euler_Problem 26 欧拉计划26题

欧拉计划26题是计算1/d(d<1000)的

欧拉计划第4题

Problem 4:         A palindromic number reads the same both ways. The...

欧拉计划第5题

原题:2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any r...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)