zoukankan      html  css  js  c++  java
  • 最大分割三角数---Python

    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
  • 相关阅读:
    Chrome调试中的奇技淫巧
    正则表达式学习记录
    探寻<a>中的href和onclick
    鼠标事件记录
    读取本地文件并进行处理
    浏览器兼容性问题汇总
    前端经验总结
    PL/sql使用总结
    正反斜杠的使用场景记录
    isEmpty和isBlank的区别
  • 原文地址:https://www.cnblogs.com/lwjl/p/4275733.html
Copyright © 2011-2022 走看看