Taxicab Numbers
The n -th taxicab number Ta(n) is the smallest number expressible as the sum of two positive cubes in n distinct ways. Find Ta(2) + Ta(3) (mod 10^9+7).
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Given is an integer sided triangle \(ABC\) with \(BC \le AC \le AB\).
\(k\) is the angular bisector of angle \(ACB\).
\(m\) is the tangent at \(C\) to the circumscribed circle of \(ABC\).
\(n\) is a line parallel to \(m\) through \(B\).
The intersection of \(n\) and \(k\) is called \(E\).

How many triangles \(ABC\) with a perimeter not exceeding \(1\,000\,000\) exist such that \(CE\) has integral length?
Problem 962: Taxicab Numbers
Mathematical Analysis
Hardy—Ramanujan Number
The most famous taxicab number is , the Hardy—Ramanujan number. The anecdote is well-known: G. H. Hardy visited Ramanujan in hospital and remarked that his cab number 1729 seemed dull. Ramanujan instantly replied it was the smallest number expressible as the sum of two cubes in two different ways:
Theorem. is the smallest positive integer with two distinct representations as a sum of two positive cubes.
Proof. Enumerate all sums with and . The cube root of 1729 is about 12.0, so . Checking all pairs, the only sums that coincide are . For all , each sum has at most one representation.
The Third Taxicab Number
was discovered by John Leech in 1957:
Verification:
- , , sum . Correct.
- , , sum . Correct.
- , , sum . Correct.
Parametric Families
Ramanujan discovered the parametric identity:
However, taxicab numbers are defined as the smallest with representations, so parametric families alone don’t suffice.
Known Taxicab Numbers
| Year discovered | ||
|---|---|---|
| 1 | 2 () | Ancient |
| 2 | 1729 | Ramanujan, 1917 |
| 3 | 87539319 | Leech, 1957 |
| 4 | 6963472309248 | Rosenstiel et al., 1991 |
| 5 | 48988659276962496 | Wilson, 1999 |
Computing the Answer
Since , the answer modulo is simply .
Derivation
Algorithm for Taxicab Numbers
Use a hash map to find collisions among sums :
- For with , compute .
- Group all pairs by their sum .
- The smallest with pairs is .
Proof of Correctness
The enumeration is exhaustive within the search range. Each pair with is considered exactly once.
Complexity Analysis
- pairs to enumerate where is the search limit.
- For : , giving pairs.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
/*
* Problem 962: Taxicab Numbers
*
* Ta(2) = 1729, Ta(3) = 87539319
* Answer = (1729 + 87539319) % (10^9 + 7) = 87541048
*
* Verification by exhaustive enumeration of a^3 + b^3.
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
const long long MOD = 1e9 + 7;
// Find Ta(2): smallest n = a^3 + b^3 with 2 representations
map<long long, int> count2;
long long ta2 = -1;
for (int b = 1; b <= 13; b++) {
for (int a = 1; a <= b; a++) {
long long s = (long long)a*a*a + (long long)b*b*b;
count2[s]++;
if (count2[s] >= 2 && (ta2 == -1 || s < ta2)) {
ta2 = s;
}
}
}
// Find Ta(3) = 87539319 (verify)
map<long long, int> count3;
long long ta3 = -1;
int lim = 445;
for (int b = 1; b <= lim; b++) {
for (int a = 1; a <= b; a++) {
long long s = (long long)a*a*a + (long long)b*b*b;
if (s > 100000000) break;
count3[s]++;
if (count3[s] >= 3 && (ta3 == -1 || s < ta3)) {
ta3 = s;
}
}
}
assert(ta2 == 1729);
assert(ta3 == 87539319);
long long ans = (ta2 + ta3) % MOD;
cout << ans << endl;
return 0;
}
"""
Problem 962: Taxicab Numbers
Ta(2) = 1729 (Hardy-Ramanujan number)
Ta(3) = 87539319 (Leech, 1957)
Answer: Ta(2) + Ta(3) mod (10^9 + 7) = 87541048
Verification by exhaustive enumeration of cube-sum representations.
"""
from collections import defaultdict
MOD = 10**9 + 7
def find_taxicab(target_reps: int, limit: int) -> tuple[int, dict]:
"""Find smallest number expressible as sum of two positive cubes
in target_reps distinct ways. Search up to limit."""
reps = defaultdict(list)
b_max = int(limit ** (1/3)) + 1
for b in range(1, b_max + 1):
for a in range(1, b + 1):
s = a**3 + b**3
if s > limit:
break
reps[s].append((a, b))
candidates = [(s, r) for s, r in reps.items() if len(r) >= target_reps]
if not candidates:
return -1, {}
candidates.sort()
return candidates[0][0], dict(candidates[:10])
# --- Compute answer ---
ta2, _ = find_taxicab(2, 2000)
ta3, _ = find_taxicab(3, 10**8)
assert ta2 == 1729
assert ta3 == 87539319
answer = (ta2 + ta3) % MOD
print(f"Ta(2) = {ta2}")
print(f"Ta(3) = {ta3}")
print(f"Ta(2) + Ta(3) = {ta2 + ta3}")
print(answer)