Periods of fractions
Suppose you have a fraction a/b where 0 < a < b, and a and b are relatively prime integers. The decimal expansion of a/b either terminates or it has an initial non-repeating part followed by a repeating part.
How long is the non-repeating part? How long is the period of the repeating part?
The answer depends on the prime factorization of the denominator b. If b has the form
b = 2I 5I^2
then the decimal expansion has r digits where r = max(I, I^2).
Otherwise b has the factorization
b = 2I 5I^2d
where d is some integer greater than 1 and relatively prime to 10. Then the decimal expansion of a/b has r non-repeating digits and a repeating part with period s where r is as above, and s is the smallest positive integer such that
d | 10s- 1,
i.e. the smallest s such that 10s - 1 is divisible by d. How do we know there exists any such integer s? This isn't obvious.
Fermat's little theorem tells us that
d | 10d - 1 - 1
and so we could take s = d - 1, though this may not be the smallest such s. So not only does s exist, we know that it is at most d - 1. This means that the period of the repeating part of a/b is no more than d - 1 where d is what's left after factoring out as many 2's and 5's from b as possible.
By the way, this means that you can take any integer d, not divisible by 2 or 5, and find some integer k such that dk consists only of 9's.
Related post: Cyclic fractions