예제 #1
0
def main():
    n = 286
    is_found = False
    T = 0

    while not is_found:
        t_n = euler.triangle_number(n)
        if euler.is_pentagonal_number(t_n) and euler.is_hexagonal_number(t_n):
            T = t_n
            is_found = True
        n += 1

    print(T )
예제 #2
0
#!/usr/bin/python
# coding: UTF-8
"""
@author: CaiKnife

Triangular, pentagonal, and hexagonal
Problem 45
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(3n1)/2     1, 5, 12, 22, 35, ...
Hexagonal       Hn=n(2n1)       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.
"""
from euler import triangle_number, pentagon_number, hexagon_number

p = set(pentagon_number(i) for i in range(1, 100000))
h = set(hexagon_number(i) for i in range(1, 100000))

for i in range(286, 100000):
    t = triangle_number(i)
    if t in p and t in h:
        print t
        break
예제 #3
0
Highly divisible triangular number
Problem 12
The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

Let us list the factors of the first seven triangle numbers:

 1: 1
 3: 1,3
 6: 1,2,3,6
10: 1,2,5,10
15: 1,3,5,15
21: 1,3,7,21
28: 1,2,4,7,14,28
We can see that 28 is the first triangle number to have over five divisors.

What is the value of the first triangle number to have over five hundred divisors?
"""

from euler import triangle_number, count_divisors

n = 1
while True:
    number = triangle_number(n)
    n += 1
    if count_divisors(number) >= 500:
        break
print number