-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path045.py
More file actions
executable file
·29 lines (22 loc) · 736 Bytes
/
045.py
File metadata and controls
executable file
·29 lines (22 loc) · 736 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
27
28
29
#!/usr/bin/python
# -*- coding: utf-8 -*-
#Triangle, 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.
#Find the next triangle number that is also pentagonal and hexagonal.
#Answer:
#1533776805
from time import time; t=time()
from mathplus import isqrt
n = 143
while True:
n += 1
hn = n*(2*n-1)
vpn = hn*6
vn = isqrt(vpn)+1
if vn % 3 == 0 and vn * (vn-1) == vpn:
print(hn)#, time()-t
break
# http://mathworld.wolfram.com/HexagonalPentagonalNumber.html