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...
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 and be two-digit positive integers with and . The fraction (with ) is a non-trivial digit-cancelling fraction if there exist a shared non-zero digit between and such that removing one occurrence of this digit from both the numerator and the denominator yields a single-digit fraction equal to .
Definition 2. For a fraction with and , the four cancellation patterns are:
| Pattern | Shared digit | Cancelled pair | Reduced fraction |
|---|---|---|---|
| P1 | units of , tens of | ||
| P2 | tens of , units of | ||
| P3 | tens of both | ||
| P4 | units of both |
Theorem 1 (Classification of Pattern P1). Under pattern P1 (, ), the equation holds if and only if
The complete set of solutions with , , and is:
Proof. Cross-multiplying the equation yields
Solving for : , so , giving .
We require: (i) , i.e., ; (ii) ; (iii) , i.e., the fraction is less than 1.
Exhaustive verification over all pairs :
- : . Check: . Condition . Valid.
- : . Check: . Condition . Valid.
- : . Check: . Condition . Valid.
- : . Check: . Condition . Valid.
All other pairs either fail the integrality condition, or produce , or violate .
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 (, ): yields , giving , hence , so . Exhaustive check over : no solution satisfies (integer) with that is not already equivalent to a P1 solution under the mapping .
Pattern P3 (, ): yields , giving , hence . But and implies , contradicting .
Pattern P4 (, ): yields , giving , hence (for ) or (trivial case excluded). If , then , a contradiction. If , the cancellation is trivial.
Thus no new solutions arise from patterns P2—P4.
Theorem 3 (Product computation). The product of the four digit-cancelling fractions, reduced to lowest terms, equals .
Proof. Using the simplified forms from Theorem 1:
Since , the fraction is already in lowest terms. The denominator is .
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 and , computes the candidate cancelled denominator digit 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 time and space.
Proof. The search iterates over exactly pairs , with arithmetic per pair. The final GCD computation operates on bounded integers. All quantities are independent of any input parameter.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#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;
}
"""Project Euler Problem 33: Digit Cancelling Fractions"""
from math import gcd
def main():
num_prod, den_prod = 1, 1
for a in range(1, 10):
for b in range(1, 10):
denom = 9 * a + b
numer = 10 * a * b
if numer % denom != 0:
continue
e = numer // denom
if e < 1 or e > 9:
continue
if 10 * a + b >= 10 * b + e:
continue
num_prod *= a
den_prod *= e
print(den_prod // gcd(num_prod, den_prod)) # 100
if __name__ == "__main__":
main()