Why do these fractions give $99...9$?
Today, as usual, we were doing all those boring numerical computations in our calculators. It all started when my professor replaced $0.2$ with $\frac{1}{5}$. I got into calculating the unit fractions one by one. But soon, I got indulged in unit fractions made from primes, as other numbers can be decomposed into prime factors (and partially because I've always thought that primes are special). Then, I observed a few things.
- All unit prime fractions (except $\frac{1}{2}$ & $\frac{1}{5}$) have recurring digits.
- But, there were a few special fractions. For instance, $\frac{1}{7}$ had a digit frequency of $6$ (i.e) $0.\overline{142857}$ - $6$ recurring digits. $\frac{1}{17}$ had a frequency of $16$, $\frac{1}{19}$ had a frequency of $18$, etc.
Only after an hour or so, I was shocked to notice something. "Most" of these primes had a similar property. If $\mathcal{R}(n)$ is the number of recurring digits, then $\mathcal{R}(n)=(n-1)$ for those special primes (Well, it doesn't work for $13$, but the latter result is still true).
Then, came the pattern. First of all, $\mathcal{R}(n)$ is even for these primes, since all primes are odd. While calculating $\frac{1}{13}$, I saw that when we split the recurring digits $0.0\overline{769230}$ in half and add them ($769+230$), we get $999=10^3-1$.
Then, I did the same for $\frac{1}{17}$ and $\frac{1}{19}$, for which I got $(10^8-1)$ and $(10^9-1)$. For every fraction of this kind, the sum is of the form $10^k-1$ where $k\ \in \mathbb N$.
Soon, I found that there was a condition for this form to appear (after writing it out for a few of these primes $7, 13, 17, 19, 23, 29$, etc.). It happens only when
$$\mathcal{R}(n_i)\geq\mathcal{R}(n_{i-1})\ \forall\ \ n \in \mathbb P$$
For instance, this doesn't happen for $1/11$, but it occurred for $1/7$ and $1/13$, since $$\mathcal{R}(11)=2\ <\ \mathcal{R}(7)=8=\mathcal{R}(13)$$
I'm curious about this result. We're slicing those recurring digits in half, right? I can't quite visualize how the summing up those sliced digits converge to the same form.
Why's this so? Is this true for all these special primes? Or, does this have a limit beyond which this condition breaks down?
So, here's what's going on here.
First of all, let's take $1/13$ for an example. Writing $1/13 = 0.\overline{076923}$ is the same as saying $\frac{1}{13} = \frac{76923}{999999} = \frac{76923}{10^{6} - 1}$. So we see that, $1/13$ having a period of 6 digits corresponds to the fact that we can write $\frac{1}{13} = \frac{a}{10^6 - 1}$ for some integer $a$. We can see $a = \frac{10^6 - 1}{13}$. So the first observation is the following:
FACT: The number of repeating digits in $1/n$ is the smallest integer $k$ such that $n$ is a factor of $10^k - 1$. (When $n$ has no factors of $2$ or $5$).
I don't know if you've seen modular arithmetic before, but saying that $n$ is a factor of $10^k - 1$ is the same as saying $10^k \equiv 1$ (mod n). The smallest such integer $k$ is called the order of 10 (mod $n$). It is not so hard to prove that, if $n$ is prime (lets call it $p$), the order of any element must divide $p - 1$. For instance, when $p = 13$, the number of repeating digits in $1/13$ must be a divisor of $12$ (and this is true in any base $b$, as long as $b$ has no factors of $13$). In usual base ten, the number of repeating digits is $6$, as you've discovered.
Okay, so now lets talk about the 9999.. part.
Suppose $p$ is a prime number such that $1/p$ has a repeating decimal expansion whose length $k$ is even (for instance, if $k = p - 1$). So we have $p$ divides $10^k - 1$, or $10^k \equiv 1$ (mod p). This implies that $10^{k/2} \equiv -1$ (mod p). Why? Well suppose $10^{k/2} \equiv x$ (mod p). Then it follows that $x^2 \equiv (10^{k/2})^2 \equiv 10^k \equiv 1$ (mod p). But the equation $x^2 \equiv 1$ only has two solutions mod $p$: $x = \pm 1$. $x = 1$ is not possible here, since we said that $k$ was the smallest integer for which $10^k \equiv 1$ (mod p).
[Note that this is not true if $p$ is not prime. For example, $10^6 \equiv 1$ (mod 21), but $10^3 \equiv 13$ (mod 21). One can check that $13$ is a solution to $x^2 \equiv 1$ (mod 21), and $13$ is neither $1$ nor $-1$. But this cannot occur when $p$ is prime.]
Okay. So we've concluded that $10^{k/2} \equiv -1$ (mod p), meaning $p$ divides $10^{k/2} + 1$. Hence we can write:
$$\frac{1}{p} = \frac{a}{10^{k/2} + 1}$$
For some integer $k$. Multiplying the numerator and denominator of the RHS by $10^{k/2} - 1$, we get:
$$\frac{1}{p} = \frac{a(10^{k/2} - 1)}{10^k - 1} = \frac{10^{k/2}(a - 1) + (10^{k/2} - a)}{10^k - 1}$$
This solves the problem! Why? Well, $10^{k/2} - a$ is a number with $k/2$ digits. Similarly, $a - 1$ is a number with $k/2$ digits. The numerator of this fraction will be $a - 1$ followed by $10^{k/2} - a$, since $a - 1$ is being multiplied by $10^{k/2}$ and so shifted $k/2$ digits. Hence the sum of the 'first half' and the 'second half' is $(a - 1) + (10^{k/2} - a) = 10^{k/2} - 1$, which is a sequence of $9$s.
I'll finish with doing $1/13$ as an example. Here $k = 6$, and so $k/2 = 3$. Then $10^{k/2} = 1000 \equiv -1$ (mod 13). Indeed, 1001 is a multiple of 13. So we can write:
$$\frac{1}{13} = \frac{77}{1001}$$
Here, $77$ is our 'a'. So we get:
$$\frac{1}{13} = \frac{77 \cdot 999}{999999} = \frac{10^3(76) + (1000 - 77)}{999999} = \frac{10^3(76) + (923)}{999999}$$
This corresponds to the fact that the first 3 digits are $a - 1 = 76$ (or 076) and the last 3 digits are $10^{k/2} - a = 1000 - 77 = 923$.
Something that might blow your mind. Not only is $142+857=999$, but $14+28+57=99$. Similarly, for $1/13=0.\overline{076923}$. You have $076+923=999$ and $07+69+23=99$.
The number of repeating digits for $\frac{1}{n}$ in general, when $n$ is relatively prime to $10$, is the smallest positive integer $q$ such that $n$ is a divisor of $10^q-1$. So, for example, $3\mid 10^1-1$, so the frequency of $1/3$ is $1$. For $7$, $10^6-1$ is divisible by $7$. When $n$ is prime, we can show that $q\mid n-1$.
Note that $10^q-1=999\dots9$, with $q$ digits $9$.
Since $37\mid 999$, we get $1/37$ has frequency $3$, which is rather extreme. Then you don't get your '999' formula, because $1/37 = 0.\overline{027}$ can't be broken into halves of digits.
Similarly, $\frac{1}{31}=0.\overline{032258064516129}$ has frequency $15$. Note that $$03226+80645+16129=99999$$
But when $q$ is even, say $q=2k$, then $n\mid 10^{2k}-1=(10^k-1)(10^k+1)$. When $n$ is prime, since $q$ is the smallest value, we know that $n$ is not a divisor of $10^k-1$, so $n$ must be a divisor of $10^k+1$. (That is why you won't see this necessarily when $n$ is not prime.)
Now, if $$\frac{1}{n}=\frac{A}{10^k}+\frac{B}{10^{2k}}+\frac{A}{10^{3k}}\dots$$ with $0\leq A,B<10^k$, we can multiply by $10^k+1$ and the result must be an integer. So:
$$\begin{align}\frac{10^k+1}{n} &= A+\frac{A+B}{10^k}+\frac{A+B}{10^{2k}}+\frac{A+B}{10^{3k}}\dots\\&=A+ \frac{10^k(A+B)}{10^k-1} \end{align}$$ This means that $A+B$ must be divisible by $10^k-1$. Since $0\leq A,B\leq 10^k-1$, the only way for this to be an integer is if $A+B=10^k-1=99\dots9$.
The cases when $q$ is divisible by $3$, as with $1/31$ and $1/37$, we saw that there is something more going on. In those cases, $q=3k$, $10^{3k}-1=(10^k-1)(10^{2k}+10^k+1)$, and by the same reasoning above, $n$ must divide $10^{2k}+10^k+1$, which means when you multiply $\frac{1}{n}$ by $10^{2k}+10^k+1$, you should get an integer, the sums of the three components, by the above reasoning, will be a multiple of $10^k-1$. (Is it possible for the sum to be $2(10^k-1)$? I haven't ruled that out...)
This can be written more generally. If $n$ is prime and not a factor of $b(b-1)$, then $\frac{1}{n}$ in base $b$ is repeating, and the sum of the (base $b$) digits will be a multiple of $b-1$. When the fraction is repeating $2$ digits, then the sum of the digits will always be $b-1$. Then above, when $q=2k$ in base $10$, this result means that $\frac{1}{n}=0.ABAB\dots$ in base $b=10^k$, and we can show that the sum must be exactly $10^k-1$.
When $n=71$, we have:
$$\frac{1}{71}=0.\overline{01408450704225352112676056338028169}$$
That sequence has length $35$, and when we break it up into set of $7$ digits, we get:
$$01408+45070+42253+52112+67605+63380+28169=299997=3\cdot99999$$
and into groups of seven digits: $$0140845+0704225+3521126+7605633+8028169=19999998= 2\cdot 9999999$$
Finally, breaking $1/7$ into groups of $5$ and $7$, and $11$, we get:
$$\begin{align}299997=&14285+71428+57142+85714+28571+42857\\ 29999997=&1428571+4285714+2857142+8571428+5714285+7142857\\ 299999999997=&14285714285+71428571428+57142857142+\\&85714285714+28571428571+42857142857 \end{align}$$
This is not just true for $n$ prime. If $n\mid 1+b+b^2+\dots b^{d-1}$ then the first $d$ digits base $b$ add up to a multiple of $b-1$. (The frequency of the repetition in $\frac{1}{n}$ will be a factor of $d$.)
For example, when $n=7\cdot 13=91$, and $91\mid 1+10^3$ and $91\mid 1+10^2+10^4$. So:
$$\frac{1}{91}=0.\overline{010989}\\01+09+89=99\\ 010+989=999$$
A fraction in lowest terms with a prime denominator other than 2 or 5 (i.e. coprime to 10) always produces a repeating decimal.
The length of the period of the repeating decimal of $1/p$ is equal to the order of $10\mod p$. If 10 is a primitive root modulo $p$, the period of the repeating decimal length is equal to $p − 1$; if not, the period of the repeating decimal length is a factor of $p − 1$. This result can be deduced from Fermat's little theorem, which states that $10^{p−1} = 1 (\mod p)$.
For $13$: $$10^1\equiv 10\pmod{13}\\10^2\equiv9\pmod{13}\\10^3\equiv12\pmod{13}\\10^4\equiv3\pmod{13}\\10^5\equiv4\pmod{13}\\10^6\equiv1\pmod{13}\\10^7\equiv10\pmod{13}$$ Here we see that the period of $10^k$ modulo $13$ is $6$. The remainders in the period, which are $10,9,12,3,4,1$ do not form a rearrangement of all nonzero remainders modulo $13$, implying that 10 is not a primitive root modulo 13.
$1/13$ contains $6$ repeating digits which indeed is a factor of $12(=13-1)$
If the period of the repeating decimal length of $1/p$ for prime $p$ is equal to $p − 1$ then the period of the repeating decimal, expressed as an integer, is called a cyclic number.Examples include $7,17,19,23,29,97,\cdots$
If $p$ is a prime and $10$ is a primitive root modulo $p$, then the length $\mathcal{R}$ of the period of the repeating decimal of $1/p$ is $\phi(p)$, totient's function.
Let suppose we take $1/p$ which is your "special prime number".Now decimal form of it must be of $$1/p=0.\overline{a_{1}a_{2}\cdots a_{\frac{p-1}2}a_{\frac{p-1}2+1}\cdots a_{p-1}}$$ Now $$10^{\frac{p-1}2}/p+1/p=\left(a_{1}a_{2}\cdots a_{\frac{p-1}2}\right).\left(\overline{a_{\frac{p-1}2+1}\cdots a_{p-1}a_{1}a_{2}\cdots a_{\frac{p-1}2}}\right)+0.\left(\overline{a_{1}a_{2}\cdots a_{\frac{p-1}2}a_{\frac{p-1}2+1}\cdots a_{p-1}}\right)$$ We can see that LHS becomes $\frac{10^{\frac{p-1}2}+1}p$ which must be an integer so your result of $999\cdots9$ automatically becomes true, since the decimal part of this number is actually the sum of half parts.