I'm trying to solve the problem:
What is the value of the first triangle number to have over five hundred divisors?
A triangle number is a number in the sequence of the sum of numbers i.e. 1+2+3+4+5...
I'm pretty sure that this is working code but I don't know because my computer is taking too long to calculate it. Does anybody have any idea of how to make the program a little faster.
Thanks.
import math
def main():
l = []
one = 0
a = 1
b = 2
while one == 0:
a = a + b
b += 1
for x in range(1, int(a/2 + 1)):
if a % x == 0:
l.append(x)
if len(l) > 499:
print a
if __name__ == '__main__':
main()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…