All Euler problems
Project Euler

Cardano Triplets

A triplet of positive integers (a, b, c) is called a Cardano Triplet if it satisfies: sqrt[3]a + bsqrt(c) + sqrt[3]a - bsqrt(c) = 1. Find the number of Cardano Triplets such that a + b + c <= 110,0...

Source sync Apr 19, 2026
Problem #0251
Level Level 12
Solved By 1,656
Languages C++, Python
Answer 18946051
Length 370 words
modular_arithmeticnumber_theoryalgebra

Problem Statement

This archive keeps the full statement, math, and original media on the page.

A triplet of positive integers \((a, b, c)\) is called a Cardano Triplet if it satisfies the condition: \[\sqrt [3]{a + b \sqrt {c}} + \sqrt [3]{a - b \sqrt {c}} = 1\] For example, \((2,1,5)\) is a Cardano Triplet.

There exist \(149\) Cardano Triplets for which \(a + b + c \le 1000\).

Find how many Cardano Triplets exist such that \(a + b + c \le 110\,000\,000\).

Problem 251: Cardano Triplets

Formal Mathematical Development

Theorem 1 (Fundamental Equation). A triple (a,b,c)(a,b,c) of positive integers satisfies a+bc3+abc3=1\sqrt[3]{a + b\sqrt{c}} + \sqrt[3]{a - b\sqrt{c}} = 1 if and only if

(a+1)2(8a1)=27b2c.(a+1)^2(8a-1) = 27b^2 c.

Proof. Set u=a+bc3u = \sqrt[3]{a + b\sqrt{c}} and v=abc3v = \sqrt[3]{a - b\sqrt{c}}. Then:

u+v=1,u3+v3=2a,u3v3=a2b2c.u + v = 1, \qquad u^3 + v^3 = 2a, \qquad u^3 v^3 = a^2 - b^2 c.

Cubing the identity u+v=1u + v = 1:

u3+v3+3uv(u+v)=1    2a+3uv=1    uv=12a3.u^3 + v^3 + 3uv(u + v) = 1 \implies 2a + 3uv = 1 \implies uv = \frac{1 - 2a}{3}.

Therefore u3v3=(uv)3=(12a)327u^3 v^3 = (uv)^3 = \frac{(1-2a)^3}{27}, which yields:

a2b2c=(12a)327.a^2 - b^2 c = \frac{(1-2a)^3}{27}.

Multiplying both sides by 27 and rearranging:

27a227b2c=(12a)3=16a+12a28a3,27a^2 - 27b^2 c = (1 - 2a)^3 = 1 - 6a + 12a^2 - 8a^3, 8a3+15a2+6a1=27b2c.8a^3 + 15a^2 + 6a - 1 = 27b^2 c.

It remains to factor the left side. Observe that a=1a = -1 is a double root of 8a3+15a2+6a18a^3 + 15a^2 + 6a - 1:

8(1)3+15(1)+6(1)1=8+1561=0,8(-1)^3 + 15(1) + 6(-1) - 1 = -8 + 15 - 6 - 1 = 0,

and synthetic division yields 8a3+15a2+6a1=(a+1)(8a2+7a1)8a^3 + 15a^2 + 6a - 1 = (a+1)(8a^2 + 7a - 1). Factoring the quadratic: 8a2+7a1=(a+1)(8a1)8a^2 + 7a - 1 = (a+1)(8a-1). Hence:

8a3+15a2+6a1=(a+1)2(8a1).8a^3 + 15a^2 + 6a - 1 = (a+1)^2(8a-1). \qquad \blacksquare

Lemma 1 (Congruence Constraint). Every Cardano triplet satisfies a2(mod3)a \equiv 2 \pmod{3}.

Proof. Since (a+1)2(8a1)=27b2c(a+1)^2(8a-1) = 27b^2 c, the left side must be divisible by 33=273^3 = 27. We analyze the 33-adic valuation.

Write v3(n)v_3(n) for the largest power of 33 dividing nn. We need 2v3(a+1)+v3(8a1)32\,v_3(a+1) + v_3(8a-1) \ge 3.

  • Case 3(a+1)3 \nmid (a+1): Then v3(a+1)=0v_3(a+1) = 0, so we require v3(8a1)3v_3(8a-1) \ge 3. But 8a12a1(mod3)8a - 1 \equiv 2a - 1 \pmod{3}, and 3(a+1)3 \nmid (a+1) means a≢2(mod3)a \not\equiv 2 \pmod{3}. If a0(mod3)a \equiv 0 \pmod{3}, then 8a11(mod3)8a - 1 \equiv -1 \pmod{3}, so v3(8a1)=0<3v_3(8a-1) = 0 < 3. If a1(mod3)a \equiv 1 \pmod{3}, then 8a11(mod3)8a - 1 \equiv 1 \pmod{3}, so v3(8a1)=0<3v_3(8a-1) = 0 < 3. Both cases fail.

  • Case 3(a+1)3 \mid (a+1): Then a2(mod3)a \equiv 2 \pmod{3} and v3(a+1)1v_3(a+1) \ge 1. Write a+1=3ta + 1 = 3t, so a=3t1a = 3t - 1. Then 8a1=24t9=3(8t3)8a - 1 = 24t - 9 = 3(8t - 3), giving v3(8a1)1v_3(8a-1) \ge 1. The total is 2v3(3t)+v3(3(8t3))21+1=32\,v_3(3t) + v_3(3(8t-3)) \ge 2 \cdot 1 + 1 = 3, which suffices.

Therefore a2(mod3)a \equiv 2 \pmod{3} is both necessary and sufficient for the divisibility by 27. \blacksquare

Theorem 2 (Parametrization). Setting a=3t1a = 3t - 1 for t1t \ge 1, the Cardano equation reduces to

t2(8t3)=b2c.t^2(8t - 3) = b^2 c.

For each tt, decompose 8t3=s2m8t - 3 = s^2 m where mm is squarefree and s1s \ge 1. Then every solution arising from this decomposition has the form a=3t1a = 3t - 1, b=tsb = ts, c=mc = m.

Proof. Substituting a=3t1a = 3t - 1 into (a+1)2(8a1)=27b2c(a+1)^2(8a-1) = 27b^2 c:

(3t)23(8t3)=27b2c    9t23(8t3)=27b2c    t2(8t3)=b2c.(3t)^2 \cdot 3(8t - 3) = 27b^2 c \implies 9t^2 \cdot 3(8t-3) = 27b^2 c \implies t^2(8t-3) = b^2 c.

Now write 8t3=s2m8t - 3 = s^2 m with mm squarefree. Then t2s2m=b2ct^2 s^2 m = b^2 c. Setting b=tsb = ts and c=mc = m gives a valid solution with cc squarefree. Moreover, since mm is squarefree, the only dd with d2md^2 \mid m is d=1d = 1, so this is the unique factorization yielding a squarefree cc from the given decomposition.

Note that different square-factor decompositions of 8t38t - 3 (when it has multiple square factors) yield distinct valid triplets. For each divisor s2s^2 of 8t38t - 3, we get a triplet (3t1,ts,(8t3)/s2)(3t-1, ts, (8t-3)/s^2). \blacksquare

Remark. The constraint a+b+cNa + b + c \le N translates to 3t1+ts+mN3t - 1 + ts + m \le N, where N=110,000,000N = 110{,}000{,}000.

Editorial

A Cardano Triplet (a, b, c) satisfies: cbrt(a + bsqrt(c)) + cbrt(a - bsqrt(c)) = 1 This reduces to (a+1)^2 * (8a-1) = 27 * b^2 * c. Setting a = 3m-1 yields m^2 * (8m-3) = b^2 * c. Parametrize: b = ef, m = er with gcd(f,r) = 1 and f^2 | (8m-3). Then c = r^2*(8m-3)/f^2, and a+b+c = (3m-1) + ef + r^2(8m-3)/f^2 <= N. For each (r, f) pair, valid e values form an arithmetic progression mod f^2.

Pseudocode

f = 1 case: closed-form count
f >= 3, odd, gcd(f,r) = 1

Complexity Analysis

Time complexity: The outer loop runs for r=O(N)r = O(\sqrt{N}) iterations. For each rr, the inner loop over ff runs while f38rNf^3 \le 8rN, i.e., f(8rN)1/3f \le (8rN)^{1/3}. The total number of (r,f)(r, f) pairs examined is bounded by r=1O(N)(rN)1/3=O(N1/3N1/2N1/6)=O(N)\sum_{r=1}^{O(\sqrt{N})} (rN)^{1/3} = O(N^{1/3} \cdot N^{1/2} \cdot N^{1/6}) = O(N), giving an overall time complexity of O(N)O(N) with small constants.

Space complexity: O(1)O(1) auxiliary storage.

Answer

18946051\boxed{18946051}

Code

Each problem page includes the exact C++ and Python source files from the local archive.

C++ project_euler/problem_251/solution.cpp
/*
 * Project Euler Problem 251: Cardano Triplets
 *
 * A Cardano Triplet (a, b, c) satisfies:
 *   cbrt(a + b*sqrt(c)) + cbrt(a - b*sqrt(c)) = 1
 *
 * Fundamental equation: (a+1)^2 * (8a-1) = 27 * b^2 * c
 * Parametrization: a = 3m-1 yields m^2 * (8m-3) = b^2 * c
 *
 * We write b = e*f, m = e*r with gcd(f,r) = 1, f^2 | (8m-3).
 * For each (r, f), valid e values form an arithmetic progression mod f^2.
 *
 * Answer: 18946051
 */

#include <bits/stdc++.h>
using namespace std;

int main() {
    const long long N = 110000000LL;
    long long count = 0;

    for (long long r = 1; r * (r + 3) <= N; r++) {
        // f = 1 case
        {
            long long coeff = 3 * r + 1 + 8LL * r * r * r;
            long long offset = 3LL * r * r + 1;
            if (coeff <= N + offset) {
                long long emax = (N + offset) / coeff;
                if (emax >= 1) count += emax;
            }
        }

        // f >= 3, odd, gcd(f, r) = 1
        for (long long f = 3;; f += 2) {
            if (f * f * f > 8LL * r * N) break;
            if (__gcd(f, r) != 1) continue;
            long long f2 = f * f;

            long long val = (8LL * r) % f2;
            if (__gcd(val, f2) != 1LL) continue;

            // Compute modular inverse of val mod f2 via extended GCD
            long long inv_val;
            {
                long long a = val, b0 = f2, x0 = 1, x1 = 0;
                while (a > 0) {
                    long long q = b0 / a;
                    b0 -= q * a; swap(a, b0);
                    x1 -= q * x0; swap(x0, x1);
                }
                inv_val = ((x1 % f2) + f2) % f2;
            }
            long long e0 = (3LL * inv_val) % f2;
            if (e0 == 0) e0 = f2;

            long long m = r * e0;
            long long h = 8LL * m - 3;
            long long s = (3 * m - 1) + e0 * f + r * r * (h / f2);
            if (s <= N) {
                long long delta = f2 * (3 * r + f) + 8LL * r * r * r;
                long long kmax = (N - s) / delta;
                count += kmax + 1;
            }
        }
    }

    cout << count << endl;
    return 0;
}