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$.