Back to Project Euler

Previous Problem Next Problem

Problem 33: Digit Cancelling Fractions

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.

Solution

All such fractions will be of the form \(\frac{10a + b}{10b + c} = \frac ac\), where \(1 \leq a,b,c \leq 9\) and \(10a + b \leq 10b + c\). There aren't that many to check. We multiply all the numerators together, multiply all the denominators together, and divide by the GCD of the two.

Python Code

from math import gcd
def p33():
	nums, dens = 1, 1
	for a in range(1, 10):
		for b in range(a, 10):
			for c in range(1, 10):
				if (10*a + b) * c == (10*b + c) * a and a < c:
					nums *= a
					dens *= c
	return dens // gcd(nums, dens)

Previous Problem Next Problem

Back to Project Euler