-
Notifications
You must be signed in to change notification settings - Fork 0
/
44.py
33 lines (30 loc) · 769 Bytes
/
44.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
def is_pentagonal(n):
delta = 1+24*n
sq_delta = delta**0.5
if sq_delta == int(sq_delta):
if not (1+sq_delta)%6: return True
return False
print is_pentagonal(1)
print is_pentagonal(5)
print is_pentagonal(12)
print is_pentagonal(22)
print is_pentagonal(35)
print is_pentagonal(51)
print is_pentagonal(70)
print is_pentagonal(92)
print is_pentagonal(117)
print is_pentagonal(145)
print is_pentagonal(122)
print is_pentagonal(23)
def problem44():
n = 1
pent = []
while True:
pent.append((n*(3*n-1))/2)
pentn = pent[-1]
for i in range(n-1):
penti = pent[i]
if is_pentagonal(penti+pentn) and is_pentagonal(pentn-penti):
return pentn-penti
n += 1
print problem44()