Why are repeating decimals often self-inversions

decimal-expansionelementary-number-theorynumber theory

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?

screenshot of examples

Best Answer

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