码迷,mamicode.com
首页 > 编程语言 > 详细

最大分割三角数---Python

时间:2015-02-05 20:02:02      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

Let us list the factors of the first seven triangle numbers:

 1: 1

 3: 1,3

 6: 1,2,3,6

10: 1,2,5,10

15: 1,3,5,15

21: 1,3,7,21

28: 1,2,4,7,14,28

We can see that 28 is the first triangle number to have over five divisors.

What is the value of the first triangle number to have over five hundred divisors?

求第一个有超过500个除数的三角数。

观察:每个三角数除以前半部分的除数,等于后半部分的除数。

from math import sqrt
import time
start=time.time()
now=2
num=1
while True:
    num=num+now
    now+=1
    t=0
    for x in range(1,int(sqrt(num))+1):
        if num%x==0:
            t+=2
    if sqrt(num)==int(sqrt(num)):
        t=t-1
    if t>500:
        break
     
print num

最大分割三角数---Python

标签:

原文地址:http://www.cnblogs.com/lwjl/p/4275733.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!