# Project Euler

## Triangular, pentagonal, and hexagonal

### Problem 45

Triangle, pentagonal, and hexagonal numbers are generated by the following formulas:

Triangle | T_{n}=n(n+1)/2 |
1, 3, 6, 10, 15, … | ||

Pentagonal | P_{n}=n(3n−1)/2 |
1, 5, 12, 22, 35, … | ||

Hexagonal | H_{n}=n(2n−1) |
1, 6, 15, 28, 45, … |

It can be verified that T_{285} = P_{165} = H_{143} = 40755.

Find the next triangle number that is also pentagonal and hexagonal.

Following from last problem, we can use similar strategy to check if a number is a triangular, pentagonal, and hexagonal by verifying the following two formulas from here:

where P(s, n) = x and s is equal to the number of sides and n is the nth s-gonal number.

Another key observation from above is that every hexagonal number is also a triangular number (you can verify this using the formula above).

Therefore, we can minimize our check by finding the next hexagonal number (starting with n = 144) and verify if it is also a pentagonal number.