The sequence of triangle numbers is generated by adding the natural
numbers. So the
triangle number would be . The first ten terms would be: Let us list the factors of the first seven triangle
numbers:
We can see that 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?
因数个数定理
如果一个正整数 分解后成为:
那么 的因数个数为:
解决方案
直接遍历所有的三角形数,用工具分解后,直接通过因数个数定理判断其因数个数是否超过.
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from tools import factorization from itertools import count
Q = 500 for i in count(1, 1): x = i * (i + 1) // 2 res = factorization(x) m = 1 for p, e in res: m *= e + 1 if m >= Q: ans = x break print(ans)