# Why are repeating decimals often self-inversions?

Let $$b$$ be any base, and let $$x$$ be some odd integer.

Empirically, it seems that for any $$b$$, the majority of odd $$x$$ will have the following property. Given a reptend $$r$$ with $$2k$$ digits as in

$$\frac{1}{x} = 0. \dots \overline{r_1 r_2 \dots r_{(2k)}} \ ,$$

you will often find that $$r_i+ r_{(k+i)}\equiv -1 \pmod b$$ for all $$i \leq k$$.

As a simple example, we have $$x=13$$ in base $$b=2$$ with the 12-digit reptend $$r=100111011000_2$$, as so:

$$\frac{1}{13} = 0.00\ \mathbf{100111}\ 011000\ \mathbf{100111}\ 011000 \ldots$$

where $$100111_2+011000_2=111111_2$$.

In short, for many more numbers than one would expect by chance, the first and second halves of the repeating digits of many rationals often sum pairwise to $$b-1$$. I haven't checked this rigorously, but there's obviously some mechanism causing this, and it seems to be base-agnostic. What gives?

Here's a follow-up snapshot of a range of essentially arbitrary rationals in the form $$\frac{20}{x}$$ using base-33. The answer about $$1/p$$ makes sense, but if it also explains why there would be so many examples in this case, I'm afraid I'm still missing how. Note the stars that indicate those whose digits sum to $$32$$, or check the reptend addition itself in the center column.

Perhaps it would be easier to explain why those rationals which don't follow this pattern do not?

• – lhf
Oct 27, 2020 at 0:43
• I read that before posting... if it addresses my question directly, I must be missing it. Oct 27, 2020 at 0:45
• note: $\frac1p$ repeats after $2k$ digits means $b^{2k}\equiv1$ and $b^{k}\equiv-1\bmod p$ Oct 27, 2020 at 0:45
• it seems you are using $k$ for two different things: (1) half the length of the reptend and (2) the odd number whose reciprocal you are calculating Oct 27, 2020 at 1:16

That the decimal expansion of $$\dfrac 1p$$ repeats after $$2k$$ digits means $$b^{2k}\equiv1\bmod p$$,

which means $$b^k\equiv\pm1\bmod p$$,

and if it doesn't repeat after $$k$$ digits that means $$b^k\equiv p-1\bmod p$$.

Thus, if $$\dfrac 1p=0.r_1r_2...r_{2k}$$, then $$(r_1r_2...r_k)\times p=b^k-(p-1)$$

and $$(r_{k+1}r_{k+2}...r_{2k})\times p=(p-1)\times b^k-1,$$

so $$(r_1r_2...r_k+r_{k+1}r_{k+2}...r_{2k})\times p = p \times( b^k-1)$$;

i.e., $$r_1r_2...r_k+r_{k+1}r_{k+2}...r_{2k} = b^k-1$$.

• Here $p$ is a power of an odd prime Oct 27, 2020 at 3:51
• Thanks, this helps, but I'm still confused about whether it helps explain non-prime cases. See addition to post. Oct 27, 2020 at 5:21
• It doesn't always work for non-prime-power cases; consider the decimal expansions of $1/119, 1/187$, and $1/221$; if $10^{2k}\equiv1\bmod pq$, it could be that $10^k\equiv-1\bmod pq$ or not Oct 27, 2020 at 15:37