-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem 45
More file actions
73 lines (54 loc) · 1.29 KB
/
Copy pathproblem 45
File metadata and controls
73 lines (54 loc) · 1.29 KB
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
68
69
70
71
72
73
"""
angle, pentagonal, and hexagonal numbers are generated by the following formulae:
Triangle Tn=n(n+1)/2 1, 3, 6, 10, 15, ...
Pentagonal Pn=n(3n−1)/2 1, 5, 12, 22, 35, ...
Hexagonal Hn=n(2n−1) 1, 6, 15, 28, 45, ...
It can be verified that T285 = P165 = H143 = 40755.
h(n) = n(2n - 1)
n = 2
h(2) = 6
6 = n(3n-1) / 2
12 = 3n^2 - n
3n^2 - n - 2 * h(n) = 0
h(i) = i (2i-1)
p(j) = j (3j-1) / 2
t(k) = k(k+1) / 2
[k(k+1) / 2 ] = k * i
t(i) + p(i+1) = h(i+1)
i(i+1) / 2 + (i+1)(3i + 3 - 1) / 2 = (i+1) (2i+2-1)
left side
i^2 + i + 3i^2 + 2 + 5i
4i^2 + 6i + 2
2i^2 + 3i + 1
right side
def triangular(num):
num = n(n+1) / 2
2 num = n^2 + n
n^2 + n - 2num = 0
a = 1
b = 1
c = -2num
-b +- sqrt(-4ac) / 2a
for i in range(inf):
num = h(i)
a, b = solve_triangle(num)
if a is integer or b is integer:
c , d = solve_pentagonal(num)
Find the next triangle number that is also pentagonal and hexagonal.
"""
def all_formulae(n, tri):
new_i = tri // n
hexa = pow(new_i, 2) * 2 - new_i
#print(new_i, hexa)
if tri / n == tri // n:
if hexa == tri:
return True
return False
pen = set()
for n in range(286, 100000000):
tri = (pow(n, 2) + n) // 2
pen.add((pow(n, 2) * 3 - n) // 2)
#print(tri, n)
if all_formulae(n, tri) and tri in pen:
print(tri)
break