All Euler problems
Project Euler

Digit Cancelling Fractions

The fraction 49/98 is a curious fraction, because an inexperienced mathematician might incorrectly simplify it by cancelling the 9s, obtaining 49/98 = 4/8, which happens to be correct. We shall con...

Source sync Apr 19, 2026
Problem #0033
Level Level 01
Solved By 79,550
Languages C++, Python
Answer 100
Length 504 words
number_theorymodular_arithmeticbrute_force

Problem Statement

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

The fraction \(49/98\) is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that \(49/98 = 4/8\), which is correct, is obtained by cancelling the \(9\)s.

We shall consider fractions like, \(30/50 = 3/5\), to be trivial examples.

There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in the numerator and denominator.

If the product of these four fractions is given in its lowest common terms, find the value of the denominator.

Problem 33: Digit Cancelling Fractions

Mathematical Development

Definition 1. Let n=10a+bn = 10a + b and d=10c+ed = 10c + e be two-digit positive integers with a,c{1,,9}a, c \in \{1, \ldots, 9\} and b,e{0,,9}b, e \in \{0, \ldots, 9\}. The fraction n/dn/d (with n<dn < d) is a non-trivial digit-cancelling fraction if there exist a shared non-zero digit between nn and dd such that removing one occurrence of this digit from both the numerator and the denominator yields a single-digit fraction equal to n/dn/d.

Definition 2. For a fraction n/dn/d with n=10a+bn = 10a + b and d=10c+ed = 10c + e, the four cancellation patterns are:

PatternShared digitCancelled pairReduced fraction
P1b=cb = cunits of nn, tens of dda/ea/e
P2a=ea = etens of nn, units of ddb/cb/c
P3a=ca = ctens of bothb/eb/e
P4b=eb = eunits of botha/ca/c

Theorem 1 (Classification of Pattern P1). Under pattern P1 (b=c0b = c \ne 0, e0e \ne 0), the equation 10a+b10b+e=ae\frac{10a + b}{10b + e} = \frac{a}{e} holds if and only if

e=10ab9a+b.e = \frac{10ab}{9a + b}.

The complete set of solutions with a,b{1,,9}a, b \in \{1, \ldots, 9\}, e{1,,9}e \in \{1, \ldots, 9\}, and 10a+b<10b+e10a + b < 10b + e is:

{(a,b,e)}={(1,6,4),  (1,9,5),  (2,6,5),  (4,9,8)}.\{(a, b, e)\} = \{(1, 6, 4),\; (1, 9, 5),\; (2, 6, 5),\; (4, 9, 8)\}.

Proof. Cross-multiplying the equation 10a+b10b+e=ae\frac{10a+b}{10b+e} = \frac{a}{e} yields

e(10a+b)=a(10b+e)    10ae+be=10ab+ae    9ae=b(10ae).e(10a + b) = a(10b + e) \implies 10ae + be = 10ab + ae \implies 9ae = b(10a - e).

Solving for ee: 9ae+be=10ab9ae + be = 10ab, so e(9a+b)=10abe(9a + b) = 10ab, giving e=10ab9a+be = \frac{10ab}{9a + b}.

We require: (i) eZe \in \mathbb{Z}, i.e., (9a+b)10ab(9a + b) \mid 10ab; (ii) 1e91 \le e \le 9; (iii) 10a+b<10b+e10a + b < 10b + e, i.e., the fraction is less than 1.

Exhaustive verification over all 8181 pairs (a,b){1,,9}2(a, b) \in \{1, \ldots, 9\}^2:

  • (1,6)(1, 6): e=60/15=4e = 60/15 = 4. Check: 16/64=1/4=0.2516/64 = 1/4 = 0.25. Condition 16<6416 < 64. Valid.
  • (1,9)(1, 9): e=90/18=5e = 90/18 = 5. Check: 19/95=1/5=0.219/95 = 1/5 = 0.2. Condition 19<9519 < 95. Valid.
  • (2,6)(2, 6): e=120/24=5e = 120/24 = 5. Check: 26/65=2/5=0.426/65 = 2/5 = 0.4. Condition 26<6526 < 65. Valid.
  • (4,9)(4, 9): e=360/45=8e = 360/45 = 8. Check: 49/98=4/8=1/249/98 = 4/8 = 1/2. Condition 49<9849 < 98. Valid.

All other pairs either fail the integrality condition, or produce e[1,9]e \notin [1, 9], or violate n<dn < d. \square

Theorem 2 (Completeness). Patterns P2, P3, and P4 yield no additional non-trivial solutions beyond those found in Theorem 1.

Proof. For each pattern, derive the analogous Diophantine condition:

Pattern P2 (a=e0a = e \ne 0, c0c \ne 0): 10a+b10c+a=bc\frac{10a + b}{10c + a} = \frac{b}{c} yields c(10a+b)=b(10c+a)c(10a + b) = b(10c + a), giving 10ac+bc=10bc+ab10ac + bc = 10bc + ab, hence a(10cb)=9bca(10c - b) = 9bc, so a=9bc10cba = \frac{9bc}{10c - b}. Exhaustive check over (b,c){1,,9}2(b, c) \in \{1, \ldots, 9\}^2: no solution satisfies a{1,,9}a \in \{1, \ldots, 9\} (integer) with 10a+b<10c+a10a + b < 10c + a that is not already equivalent to a P1 solution under the mapping (n,d)(n,d)(n, d) \mapsto (n, d).

Pattern P3 (a=ca = c, e0e \ne 0): 10a+b10a+e=be\frac{10a + b}{10a + e} = \frac{b}{e} yields e(10a+b)=b(10a+e)e(10a + b) = b(10a + e), giving 10ae=10ab10ae = 10ab, hence e=be = b. But e=be = b and a=ca = c implies n=dn = d, contradicting n<dn < d.

Pattern P4 (b=eb = e, c0c \ne 0): 10a+b10c+b=ac\frac{10a + b}{10c + b} = \frac{a}{c} yields c(10a+b)=a(10c+b)c(10a + b) = a(10c + b), giving cb=abcb = ab, hence c=ac = a (for b0b \ne 0) or b=0b = 0 (trivial case excluded). If c=ac = a, then n=dn = d, a contradiction. If b=0b = 0, the cancellation is trivial.

Thus no new solutions arise from patterns P2—P4. \square

Theorem 3 (Product computation). The product of the four digit-cancelling fractions, reduced to lowest terms, equals 1/1001/100.

Proof. Using the simplified forms from Theorem 1:

1664×1995×2665×4998=14×15×25×12=11214552=2200=1100.\frac{16}{64} \times \frac{19}{95} \times \frac{26}{65} \times \frac{49}{98} = \frac{1}{4} \times \frac{1}{5} \times \frac{2}{5} \times \frac{1}{2} = \frac{1 \cdot 1 \cdot 2 \cdot 1}{4 \cdot 5 \cdot 5 \cdot 2} = \frac{2}{200} = \frac{1}{100}.

Since gcd(1,100)=1\gcd(1, 100) = 1, the fraction is already in lowest terms. The denominator is 100100. \square

Editorial

We use the algebraic relation derived for non-trivial digit cancellation to avoid checking all two-digit fractions directly. The search runs over the nonzero digits aa and bb, computes the candidate cancelled denominator digit ee from the divisibility condition, and retains only those cases that produce a proper fraction. The valid fractions are then multiplied together in cancelled form, and the denominator of the reduced product is returned.

Pseudocode

Algorithm: Non-trivial Digit-cancelling Fractions
Require: The nonzero decimal digits.
Ensure: The denominator of the product of all non-trivial digit-cancelling fractions, written in lowest terms.
1: Initialize N ← 1 and D ← 1.
2: For each ordered pair of nonzero digits (a, b), compute e ← 10ab / (9a + b) whenever this quotient is an integer digit.
3: If e is a digit and 10a + b < 10b + e, record the fraction (10a + b) / (10b + e) = a / e by updating N ← N · a and D ← D · e.
4: Reduce the fraction N / D to lowest terms.
5: Return the reduced denominator.

Complexity Analysis

Proposition. The algorithm runs in O(1)O(1) time and O(1)O(1) space.

Proof. The search iterates over exactly 8181 pairs (a,b){1,,9}2(a, b) \in \{1, \ldots, 9\}^2, with O(1)O(1) arithmetic per pair. The final GCD computation operates on bounded integers. All quantities are independent of any input parameter. \square

Answer

100\boxed{100}

Code

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

C++ project_euler/problem_033/solution.cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    int num_prod = 1, den_prod = 1;
    for (int a = 1; a <= 9; a++) {
        for (int b = 1; b <= 9; b++) {
            int denom = 9 * a + b;
            int numer = 10 * a * b;
            if (numer % denom != 0) continue;
            int e = numer / denom;
            if (e < 1 || e > 9) continue;
            if (10 * a + b >= 10 * b + e) continue;
            num_prod *= a;
            den_prod *= e;
        }
    }
    cout << den_prod / __gcd(num_prod, den_prod) << endl;  // 100
    return 0;
}