Number theory question involving repeating decimals of $\frac1{p}$ for prime $p$

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.

I think this should be true. Here's my reasoning:

To begin with, let's formalize the concept of the number of repeating decimals. If you've done this kind of long division by hand then you will know that the decimals repeat when we get a remainder of $$1$$ on some iteration. This essentially means that if $$\frac{1}{p}$$ has $$r$$ repeating digits, then $$10^r \equiv 1 \pmod{p}.$$ To be more precise, we should have that the number of repeating decimals is the smallest such $$r$$ which satisfies this, because if there was a smaller number then the digits would repeat then instead. Now that we have a uniquely defined value for the number of repeating digits (supposing the digits repeat, which is true for prime numbers greater than $$5$$) let this be represented by the function $$r(n)$$ from now on.

Now for our prime number $$p$$ suppose that we have $$r(p) = m \cdot r_x,$$ where $$m$$ and $$r_x$$ are integers and $$r_x \neq r(p).$$ We can do this whenever $$r(p)$$ is not $$1,$$ which it will not be for any prime number $$p > 5.$$ Because $$r(p)$$ must be the smallest value $$r$$ such that $$10^r \equiv 1 \pmod{p},$$ we must have that $$10^{r_x} \not\equiv 1,$$ or equivalently that $$10^{r_x} - 1 \not\equiv 0.$$ Because $$p$$ is prime, this is equivalent to saying that $$10^{r_x} - 1$$ is coprime with $$p.$$

Now, by consequence of Euclid's lemma, we can say that $$10^{r(p)} - 1 \equiv 0 \pmod{p}$$ implies that $$\frac{10^{r(p)} - 1}{10^{r_x} - 1} \equiv 0 \pmod{p}.$$ To be clear this only holds if the left-hand side is still an integer, but we know this to be the case because we can apply a famous identity for geometric sums, $$\sum_{k = 0}^n r^k = \frac{r^{n+1} - 1}{r - 1}.$$ So, we can rewrite our result as $$\sum_{k = 0}^{m-1} 10^{kr_x} \equiv 0 \pmod{p},$$ which is to say that the sum is divisible by $$p.$$

This may seem like a fairly random statement, but believe it or not this is actually pretty much what we've set out to prove. To see why, think a bit more in-depth about what you're doing when you concatenate your number $$n$$ with itself $$m$$ times. You're really starting with your number $$n,$$ then adding a copy of the number which has been shifted $$r_x$$ places to the left, which is to say you add $$n \cdot 10^{r_x}.$$ Then you repeat this process of multiplying $$10^{r_x}$$ and adding the copies on until you have $$r(p)$$ digits, which means you have to make $$m$$ copies with $$r_x$$ digits each. What you should get at the end would be $$N = \sum_{k = 0}^{m - 1} n \cdot 10^{kr_x},$$ noting that the upper bound is $$m-1$$ because $$k$$ starts at $$0.$$ Now, because $$n$$ is a constant with respect to the sum, we can simply pull out the $$n$$ to get $$N = n \cdot \sum_{k = 0}^{m - 1} 10^{kr_x}.$$ And finally, because we showed before that $$\sum_{k = 0}^{m - 1} 10^{kr_x}$$ is divisible by $$p, N$$ should also be divisible by $$p$$ regardless of our choice of $$n.$$

Sorry if I lost you in there, I know you said you're not a mathematician so I'd understand if that was a bit hard to follow. In any case, thank you for the question, I had a lot of fun figuring this out!

Edit: a while after writing this I thought of an interesting addendum which I wanted to share. The base $$10$$ is not important to the meat of this argument, so it should work for a number system with an arbitrary base, so long as the appropriate restrictions are made on the primes you use.

As an example, consider $$\frac{1}{11_{10}}$$ in binary, which is represented as $$0.\overline{0001011101}_2.$$ This has $$10$$ repeating digits, so our eligible factors are $$1,2,$$ and $$5.$$ Checking the corresponding sums gives us $$1111111111_2 = 1023_{10}, 101010101_2 = 341_{10},$$ and $$100001_2 = 33_{10},$$ all of which are divisible by $$11_{10}.$$

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

• I was about to write the same thing,but you are fast :)
– IITM
Jun 1, 2021 at 3:40
• I'm not sure why you say this works for $3,$ it has only one repeating digit so there is no way to choose an integer $d$ which divides $r$ but is not equal to $r.$ And removing the restriction $d \neq r$ breaks the whole thing because we can no longer say $10^d - 1$ is not divisible by $p.$ (also, not trying to start a fuss but I would like to point out that our arguments are pretty much the same, only written from different angles) Jun 1, 2021 at 4:03
• @StephenDonovan okay, I'd say it is vacuously true for $p=3$: that case has no real content. I didn't remove the restriction $d \not= r$, so if $r = 1$ then there is nothing to do. It's not as if that case presents a counterexample (unlike for $p = 2$ and $5$). For a general base $b > 1$, the result applies for each prime $p$ not dividing $b$. We have $r = 1$ when $p \mid (b-1)$. You could choose not to allow $p$ dividing $b-1$, but I think it's better to allow all $p$ not dividing $b$ and have a result for proper factors $d$ of $r$. If there are no such $d$ then it's boring, not wrong.
– KCd
Jun 1, 2021 at 4:30
• @StephenDonovan I agree that our arguments are basically the same.
– KCd
Jun 1, 2021 at 4:33
• Fair enough, I was thinking of this "working" in terms of us being able to go through the process successfully and obtaining an interesting result, instead of as a measurement of the truth of a statement. Jun 1, 2021 at 4:37