TITLE: Number theory question involving repeating decimals of $\frac1{p}$ for prime $p$
QUESTION [5 upvotes]: I'm not mathematician so I can't write it down in mathematical language, and I can only explain  rambling words with almost no mathematical language...
I'm re-posting this problem, because my former question was closed, and I don't know what to do about that.
So, the basic rule is this.
Choose a prime number $p$ greater than $5$
ex) $p=7$
Calculate $\frac{1}{p}$ and find the number of repeating decimal digits. Call this $r.$
ex) when $p=7, r=6$
Find all the divisors of $r,$ except $r$ itself, and name them $r_i.$
ex)when $r=6, r_1=1, r_2=2, r_3=3$
Choose any $r_x.$
ex) $r_x=3$
Choose any random $r_x$-digit number, and name it $n.$
ex) when $r_x=3,   n=171$
Concatenate $n$ with itself several times to create an $r$ digit number (always possible since $r_x$ is the divisor of $r$), and name it $N$
ex) when $n=171, N=171171$
This final number $N$ you created will be divided by the prime number you chose without remainder.
ex)$\frac{171171}{7}=24453$
Is this always true?
for the understanding, I made a video explaining about what I found.
https://www.youtube.com/watch?v=g1ZzXkQeN0I
Hope this is not against the policy of this page.

REPLY [2 votes]: This is true and it will work when $p$ is a prime other than $2$ or $5$. In particular, it works for $p = 3$ although you took $p > 5$.
The fraction $1/p$ has a periodic decimal whose period $r$ is the smallest exponent where $10^r - 1$ is divisible by $p$.  (In the notation of modular arithmetic, $10 \bmod p$ has order $r$, and this link between decimal periods and modular arithmetic can be used to answer nearly all answerable questions about periodic decimals, e.g., this explains why $r$ is a factor of $p-1$. The connection between periodic decimals and modular arithmetic goes back to Gauss.)
Let $d$ be a divisor of $r$ except for $r$ (you write $r_x$ for $d$) and let $n$ be a $d$-digit number in base $10$.  To concatenate $n$ to get an $r$-digit number $N = nn\cdots n$ in base $10$, how many $n$'s do we need?  Let $e = r/d$, so we use $e$ copies of $n$ to create $N$. That is how $N$ has $r$ digits ($r = de$).   We now want to find a formula for $N$ that explains why $N$ is divisible by $p$.
Let's look at a pattern in concatenating $n$ a few times. Two $n$'s is
$nn = n 10^d + n$ since we multiply by $10^d$ to push the leftmost copy of $n$ entirely in front of the rightmost copy of $n$. Similarly,
three $n$'s is
$nnn = n 10^{2d} + n 10^d + n$.  In general, when we have $e$ copies of $n$ we need to multiply the different $n$'s by $1$, $10^d$, $10^{2d}$, and so on up to $10^{(e-1)d}$ for the leftmost $n$.  That means
$$
N = n 10^{(e-1)d} + \cdots + n 10^{2d} + n 10^d + n.
$$
The role of $n$ here is as a multiplying factor by all the powers of $10$, so factor it out:
$$
N = n(10^{(e-1)d} + \cdots + 10^{2d} + 10^d + 1).
$$
On the right side is a finite geometric series. For $t \not= 1$,
$$
t^{e-1} + t^{e-2} + \cdots + t + 1 = \frac{t^e-1}{t-1}.
$$
Using this with $t = 10^d$,
$$
N = n\frac{(10^d)^e-1}{10^d-1} = n\frac{10^r-1}{10^d-1}.
$$
From the start of this answer, $10^r - 1$ is divisible by $p$.
Because $r$ is minimal with that property and $d < r$, $10^d-1$ is not divisible by $p$.  Since $p$ is prime and divides the numerator $10^r-1$ but not the denominator $10^d-1$, it divides the ratio. Thus $p$ is a factor of $N$.
As Stephen Donavan observed in his answer, nothing here really requires the base to be $10$. Pick an integer $b > 1$ (you used $b=10$). When $p$ is prime and does not divide $b$, the base $b$ expansion of $1/p$ is purely periodic and its period $r$ is the smallest positive integer such that $b^r - 1$ is divisible by $p$.  (In terms of modular arithmetic, the base $b$ period of $1/p$ is the order of $b \bmod p$, but you can ignore that if you don't know what it means.) If $d$ is a proper factor of $r$ and you pick a positive integer $n$ that has $d$ digits in base $b$, and let $N = nn\cdots n$ be an $r$-digit number in base $b$ formed by concatenating $n$ enough times then $N$ is divisible by $p$. The reason is exactly the same as what I wrote above, with $10$ replaced everywhere by $b$.