How can I show cyclical patterns in base 10 representation of fractions?

83 Views Asked by At

My problem is this: given a fraction $ \frac {1} {d} $ where $d$ is an integer, convert to a decimal fraction, like say $ \frac {1} {6} = 0.166666... $ then identify how many digits is in the repeating part of the fraction. This is a problem on a programming challenge problem website, so it can be solved with code. I won't mention which website so that I don't spoil it for anyone else doing a Google search. I am a computer science tutor and want to explain this to a student of mine, so I want to make sure I understand it well.

To make this a little easier to consider for myself (not being too familiar with the relevant math), I considered just the integer result of dividing some power of 10 by d: say $ \frac {100} {6} = 16$. Then we notice $ \frac{1000} {6} = 166$. Hmm, this seems like progress: we can observe the repeating pattern in the result of the division.

Say $d = 7$. Note that $\frac {10^6} {7} = 142857$ and $ \frac{10^{12}}{7} = 142857142857$. Okay this seems like good evidence that the cycle length for $ d=7$ is 6. I could probably write code to check this. But I feel a bit uncomfortable knowing how to identify a cycle, or not having the mathematics to back up my algorithm for finding a cycle.

I did write some code that got the right answer, but I still don't feel I understand.

So I made an attempt to understand further. I noticed that when we divide by increasing powers of ten, we get not just an integer but a remainder. So if $$ \frac{10^p} {d}$$ has a remainder of $r_1$, we can write $$ 10^p \cong r \mod d $$ I have this intuitive sense that as we track remainders as we increase the power of ten, at some point we'll get a remainder we had earlier, and the number of times we took an increasing power of ten is the cycle length. So if $$ 10 ^ p \cong 10^q \mod d$$ then $$ 10 ^ {p+1} \cong 10 ^ {q+1} \mod d$$ which I believe follows from the laws of modular arithmetic.

Then I can intuitively see that $q-p$ is some multiple of the cycle length, and the smallest q such that $ 10 ^ p \cong 10^q \mod d$ means $q-p$ is the cycle length exactly.

But two things: #1 I don't feel clear enough on why this works and #2 I need to explain this to a 9th grader, so I'm hoping there's a simple way to see it better.