-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path45.py
67 lines (45 loc) · 860 Bytes
/
45.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sys, math
def pent(n):
return n*(3*n-1)/2
def tri(n):
return n*(n+1)/2
def hex(n):
return n*(2*n-1)
def is_int(n):
if n - int(n) > 0:
return False
return int(n)
def is_pent(P):
n = (math.sqrt((24*P)+1)+1)/6
return is_int(n)
def is_tri(T):
n = (-1 + math.sqrt(1 + 8*T))/2
return is_int(n)
def is_hex(H):
n = (1 + math.sqrt(1 + 8*H))/4
return is_int(n)
i = 286
while True:
if is_pent(tri(i)):
if is_hex(tri(i)):
print tri(i)
break
else:
i+=1
else:
i+=1
# for e in [1,3,6,10,11]:
# print(is_tri(e))
# for e in [1,5,12,22,23]:
# print(is_pent(e))
# for e in [1,6,15,28,29]:
# print(is_hex(e))
# T = n(n+1)/2
# P = n(3n-1)/2
# H = n(2n-1)
# n**2 + n - 2*T = 0
# 3*n**2 - n - 2*P = 0
# 2*n**2 - n - H = 0
# (-1 + math.sqrt(1 + 8*T)/2 = n
# (1 + math.sqrt(1 + 24*P))/6 = n
# (1 + math.sqrt(1 +8*H))/4 = n