The 12th problem is :
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?
My program in Python 3.4
def Nfactor(n):
k=2
c=0
while k<=n:
if n%k==0:
n=n//k
c+=1
else:
k=k+1
return c
a=1
for i in range(10**6):
a+=i
if Nfactor(a)>=500:
print(a)
break
I waited more than 10 minutes and never have an answer. And for my own my program is not too bad and must run in seconds.. well it makes me crazy lol i didn't find my mistake.
Can you help me please?
Thank you in advance !
EDIT
My solution now :
import math
def Nfactor(n):
if n==1:
return 1
else:
c=0
for i in range(1, int(math.sqrt(n)+1)):
if n%i==0:
c+=1
return c*2
a=0
for i in range(1,10**6):
a+=i
if Nfactor(a)>=500:
print(a)
break