小白也能看得懂的服务端性能测试指标及问题排查

Mysql_窗口函数_OVER()的分组参数PARTITION BY

  返回  

Project Euler(欧拉计划) ——Problem12:Highly divisible triangular number

2021/8/21 19:41:29 浏览:

Project Euler(欧拉计划) ——Problem12:Highly divisible triangular number

题目

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 个除数的三角形数的值是多少?

求解

def istriangle(x):
    s = 1
    i = 2
    while s<x:
        s = s+i
        i += 1
    if s==x:
        return True
    else:
        return False

def num(x):
    s = 0
    for i in range(1,x+1):
        if x%i == 0:
            s += 1
    return s
num(10)

s = 0
i = 1
while s<501:
    if istriangle(i):
        s = num(i)
        i += 1
    else:
        i += 1
        continue
print(i-1)

结果:76576500

联系我们

如果您对我们的服务有兴趣,请及时和我们联系!

服务热线:18288888888
座机:18288888888
传真:
邮箱:888888@qq.com
地址:郑州市文化路红专路93号