-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp012.py
More file actions
26 lines (25 loc) · 692 Bytes
/
Copy pathp012.py
File metadata and controls
26 lines (25 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from euler import sieve_eratosthenes
if __name__ == '__main__':
primes = sieve_eratosthenes(1000000)
div_req = 500
tri = 0
i = 1
while True:
tri = tri + i
i = i + 1
# find number of divisors
# do the prime factorization and use exponents
# of primes in factorization
div = 1
tmp = tri
for p in primes:
cnt = 0
while tmp % p == 0:
tmp = tmp/p
cnt += 1
div = div*(cnt+1)
if tmp == 1:
break
if div > div_req:
print('First triangle number to have over 500 divisors: %d' % tri)
break