Lesson goal: Contest Diophantine: Repeating Decimals (AMC 10A Problem 17)

Previous: Contest Combinatorics: Pairing Numbers | Home | Next: Contest Number Theory: GCD and LCM

In the 2022 AMC 10A competition, Problem #17 links repeating decimal fractions to integer equations:

Contest Problem Statement:
"How many three-digit positive integers $abc$ are there whose nonzero digits $a, b,$ and $c$ satisfy
$$0.\overline{abc} = \frac{1}{3}(0.\overline{a} + 0.\overline{b} + 0.\overline{c}) \text{ ?"}$$
(The bar indicates digit repetition; thus $0.\overline{abc}$ is the infinite repeating decimal $0.abcabc\dots$)."


From Repeating Decimals to Fractions

Recall the fraction formula for repeating decimals:
  • A single-digit repeating decimal has denominator $9$:
    $$0.\overline{a} = \frac{a}{9}, \quad 0.\overline{b} = \frac{b}{9}, \quad 0.\overline{c} = \frac{c}{9}$$
  • Their sum divided by $3$ is:
    $$\frac{1}{3}\left(\frac{a}{9} + \frac{b}{9} + \frac{c}{9}\right) = \frac{a + b + c}{27}$$
  • A three-digit repeating block has denominator $999$:
    $$0.\overline{abc} = \frac{100a + 10b + c}{999}$$
Equating the two expressions:
$$\frac{100a + 10b + c}{999} = \frac{a + b + c}{27}$$
Since $999 = 27 \times 37$, multiplying both sides by $999$ yields:
$$100a + 10b + c = 37(a + b + c)$$
Expanding and collecting terms:
$$100a + 10b + c = 37a + 37b + 37c$$
$$63a = 27b + 36c$$
Dividing both sides by $9$ gives a clean linear Diophantine equation:
$$7a = 3b + 4c$$
where $a, b, c \in \{1, 2, 3, 4, 5, 6, 7, 8, 9\}$ are nonzero digits.

Finding the Solutions with Prolog

Notice that if $a = b = c$, then $7a = 3a + 4a = 7a$ holds automatically for all $9$ repeating numbers: $111, 222, \dots, 999$.
Are there any other solutions where the digits are not all equal?

Let's let Prolog search all digit combinations and find every single solution!
abc_number(A, B, C, N) :- digit(A), digit(B), digit(C),% Diophantine equation 7*a = 3*b + 4*c: Replace ???? with 4 7 * A =:= 3 * B + ???? * C,N is 100 * A + 10 * B + C.
Move the mouse over a dotted box for more information.

Prolog generates all candidate digit triples, applies the arithmetic relation, and enumerates all 13 valid three-digit integers.

Now you try. Replace ???? with 4 and click Run to find all 13 valid repeating decimal integers. Then check Example 1 to test each fraction verification directly, or Example 2 to find which solutions have distinct digits!

Type your code here:


See your results here: