Triangular, Pentagonal, and Hexagonal
Triangle, pentagonal, and hexagonal numbers are generated by the following formulae: | Type | Formula | Sequence | |------------|----------------------------|-----------------------| | Triangle | T...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:
| Triangle | ||||
| Pentagonal | ||||
| Hexagonal |
It can be verified that
Find the next triangle number that is also pentagonal and hexagonal.
Problem 45: Triangular, Pentagonal, and Hexagonal
Mathematical Development
Mathematical Foundation
Theorem 1. Every hexagonal number is a triangular number. Specifically, for all positive integers .
Proof. Let . We claim :
Lemma 1. The converse of Theorem 1 fails: not every triangular number is hexagonal. Specifically, is hexagonal if and only if is odd.
Proof. If , then , so , which is odd. Conversely, if is odd, then .
Theorem 2 (Reduction to hexagonal-pentagonal search). A number is simultaneously triangular, pentagonal, and hexagonal if and only if it is both hexagonal and pentagonal.
Proof. () Immediate.
() If is hexagonal, then by Theorem 1, so is triangular. Combined with being pentagonal, is all three.
Theorem 3 (Pentagonal number test). A positive integer is pentagonal if and only if is a positive integer.
Proof. The equation gives , i.e., . By the quadratic formula, (taking the positive root). This is a positive integer if and only if (i) is a perfect square and (ii) .
Theorem 4 (Pell equation structure). The equation , i.e., , reduces to the generalized Pell equation via the substitution (scaled) and (scaled), or more precisely, to an integer recurrence.
Proof. Setting :
Let and . Then and . Substituting and simplifying:
The equation gives , i.e., , or equivalently , which is with . This is a generalized Pell equation whose solutions form a recurrence:
with initial solutions generating the sequence of hexagonal-pentagonal numbers. The solutions after yield .
Theorem 5. The next number after that is simultaneously triangular, pentagonal, and hexagonal is .
Proof. By Theorem 2, we search hexagonal numbers for and test pentagonality via Theorem 3. By the Pell equation structure (Theorem 4), the next solution is at :
Verifying pentagonality: . Since , the number is pentagonal.
Verifying triangularity: .
Editorial
Since every hexagonal number is automatically triangular, it is enough to enumerate hexagonal numbers beyond the known value and test only for pentagonality. Starting from , we compute and apply the discriminant criterion for pentagonal numbers. The first hexagonal number that passes this test is therefore the next number that is simultaneously triangular, pentagonal, and hexagonal.
Pseudocode
Algorithm: Next Triangular-Pentagonal-Hexagonal Number
Require: The hexagonal sequence H_m = m(2m - 1).
Ensure: The first value after 40755 that is simultaneously triangular, pentagonal, and hexagonal.
1: Initialize m ← 144.
2: Repeat:
3: Compute H ← m(2m - 1).
4: If H is pentagonal, return H; otherwise update m ← m + 1.
Complexity Analysis
Time (brute-force search): We iterate hexagonal numbers from to , performing an pentagonal test at each step. Total: where , i.e., iterations.
Time (Pell equation): Using the recurrence from Theorem 4, each solution is computed in from the previous one, giving per solution after finding the recurrence.
Space: .
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
bool is_pentagonal(long long v) {
if (v <= 0) return false;
long long disc = 1 + 24 * v;
long long s = (long long)sqrt((double)disc);
while (s * s < disc) s++;
while (s * s > disc) s--;
if (s * s != disc) return false;
return (1 + s) % 6 == 0;
}
int main() {
// Every hexagonal number is triangular: H_m = T_{2m-1}.
// So we just iterate hexagonal numbers and check if pentagonal.
// Start after H_143 = 40755.
for (long long m = 144; ; m++) {
long long h = m * (2 * m - 1);
if (is_pentagonal(h)) {
cout << h << endl;
return 0;
}
}
return 0;
}
import math
def is_pentagonal(v):
"""Check if v is a pentagonal number."""
if v <= 0:
return False
disc = 1 + 24 * v
s = math.isqrt(disc)
if s * s != disc:
return False
return (1 + s) % 6 == 0
def solve():
"""Find the next number after 40755 that is triangular, pentagonal,
and hexagonal.
Key insight: every hexagonal number H_m = m(2m-1) equals T_{2m-1},
so all hexagonal numbers are triangular. We only need to find the
next hexagonal number that is also pentagonal.
"""
m = 144 # Start after H_143 = 40755
while True:
h = m * (2 * m - 1)
if is_pentagonal(h):
print(h)
return
m += 1
solve()