Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- inline constexpr int64_t pentagonal(const int &n) {
- return n * (3 * n - 1LL) >> 1;
- }
- inline constexpr int64_t hexagonal(const int &n) {
- return n * (2 * n - 1LL);
- }
- bool isTriagonal(const int64_t &n) {
- const int s = sqrt(n << 1);
- return n << 1 == s * (s + 1LL);
- }
- bool isPentagonal(const int64_t &n) {
- const int s = sqrt(n * 2 / 3);
- return n == pentagonal(s) || n == pentagonal(s + 1) || n == pentagonal(s + 2) || n == pentagonal(s - 1) || n == pentagonal(s - 2);
- }
- signed main() {
- ios::sync_with_stdio(0);
- cin.tie(0); cout.tie(0);
- int i = 144;
- while (!isPentagonal(hexagonal(i)) || !isTriagonal(hexagonal(i))) ++i;
- cout << hexagonal(i);
- }
Advertisement