-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12.py
44 lines (37 loc) · 1.07 KB
/
12.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
######################################################################################
# What is the value of the first triangle number to have over five hundred divisors? #
######################################################################################
import math
ltn = []
for i in range(12000, 15000):
ltn.append(i*(i + 1) / 2)
def lpf_modified(n):
l = {}
while n % 2 == 0:
if 2 in l:
l[2] += 1
else:
l[2] = 1
n //= 2
for i in range(3, math.ceil(math.sqrt(n)) + 2, 2):
while n % i == 0:
if i in l:
l[i] += 1
else:
l[i] = 1
n //= i
if n > 1:
l[n] = 1
return l
def nod(lpf_d):
nod = 1
for key in lpf_d:
nod *= lpf_d[key] + 1
return nod
for e in ltn:
n = nod(lpf_modified(e))
if n > 500:
print(e)
################################################################
# https://mathschallenge.net/library/number/number_of_divisors #
################################################################