-
Notifications
You must be signed in to change notification settings - Fork 2
/
p045.py
54 lines (49 loc) · 1.07 KB
/
p045.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
#!/usr/bin/env python
#
# Project Euler
#
# Problem 45
# Triangle number = n(n+1)/2
# Pentagonal number = n(n+1)/2
# Hexagonal number = n(2n-1)
# Find the next triangle number that is also pentagonal and hexagonal
# after 40755.
def istrinum(n):
x=(8*n+1)**(0.5)
#print x
return int(x)==x
def ispentnum(n):
x=((24*n+1)**(0.5)+1)/6
#print x
return int(x)==x
def ishexnum(n):
x=((8*n+1)**(0.5)+1)/4
#print x
return int(x)==x
if __name__ == "__main__":
term=144
i=term*(2*term-1)
# all hexnums are trinums, so no need to check for trinums
#istrin = istrinum(i)
#ispentn = ispentnum(i)
#ishexn = ishexnum(i)
while not ispentnum(i):
i=term*(2*term-1)
term+=1
#istrin=istrinum(i)
#ispentn=ispentnum(i)
#ishexn=ishexnum(i)
'''if i%10000==0: print i
if ispentnum(i)==True:
if ishexnum(i)==True:
print i
exit()
else: i+=1; continue
else: i+=1; continue'''
#if trin==False or pentn==False or hexn==False:
# i+=1
#if trin==True and pentn==True and hexn==True: print i; exit()
print istrinum(i)
print ispentnum(i)
print ishexnum(i)
print i