# Average period of the decimal expansion of reciprocals of prime numbers

Let $$P(n)$$ be the period of the decimal expansion of $$1/n$$, for prime $$n$$ (e.g. $$1/7=0.\overline{142857}\rightarrow P(7)=6$$). The value of $$P(n)$$ fluctuates heavily, but it seems to have an average behavior that is more easily visible by considering the function $$S(x)=\sum_{k=1}^{x}P(p_k)$$ Where $$p_k$$ is the kth prime. Below is the graph of $$S(x)$$.

A power regression gives the following approximation with an $$R^2$$ of $$0.9998753$$ $$S(x)\approx0.94782x^{2.11976}$$ which would imply that the average value/approximation of $$P(p_n)$$ around $$p_n$$ is $$P(p_n)\approx 0.94782(n^{2.11976}-(n-1)^{2.11976})$$ Is there a way to derive this behavior other than empirically?

This question was inspired by another similar problem related to the Collatz conjecture.

• I have no proof of this, but empirically $\lim_{n\rightarrow\infty}[\sum_n P(p_n)] /[ \sum_n p_n]$ seems to be the Euler-Mascheroni constant. Commented Oct 26, 2022 at 1:37
• @eyeballfrog I don't know if it is the Euler-Mascheroni constant, but it does seem to converge to some value close to it. If it does converge, then the problem can be solved in terms of the sum of primes, instead of the sum of the periods of their decimal expansions. Commented Oct 26, 2022 at 2:17
• $P(n)$ seems to always be $\frac{n-1}{k}$ for some integer $k$. If there exists some proportion $r_k$ of prime numbers that satisfy $P(n)=\frac{n-1}{k}$, then, I believe, it would mean that $\sum_{k=1}^{x}P(p_k)\approx\sum_{t=1}^{\infty}\left(r_t\sum_{k=1}^{x}\frac{p_k-1}{t}\right)$, which could explain the problem, but I don't know anything about $r_k$ other than the fact that it decreases as $k$ gets larger. Commented Oct 26, 2022 at 2:37
• Two empirical things about $r_k$: it seems $r_k\sim k^{-2}$ for large $k$ (but not so large that $r_k$ can be $0$), and $r_1\approx 1/e$. That first one suggests connections to $\zeta(3)$, though I'm not sure where the second one leads. Commented Oct 26, 2022 at 12:00

Excellent question. I've provided some relevant literature (with a description of how to go about finding it) and a potential bound that seems to match yours numerically.

First, and for general advice, this is exactly the type of question that is well-suited to a literature search starting with the OEIS, as it. . .

• . . . pertains to a sequence . . . that is in integers.

• . . . is a question that is natural to ask and simple to communicate.

• . . . has a rather pure, number theoretic flavor (i.e., focusing on numbers/objects/algorithms themselves and their properties, divorced from any specific contexts).

• . . . admits a sufficiently unique sequence for the search to be direct.

After finding a relevant OEIS sequence, a literature search can become far easier, since the OEIS page itself can cross-reference literature but also since the OEIS index can grant a convenient term to refer to the problem when searching elsewhere (search engines, scholar, MSE, MO, approach0, etc.)

And indeed, after searching the first few terms, we are successful and find the sequence to be OEIS Sequence A002371. We can then cross-reference to earlier literature, which may have been cited by later work. We may find that George Salmon and William Shanks studied the sequence in the late 19th century. With this in mind, we may find a Scholar link to Shanks' paper with 5 citations, including Knudsen, The Discovery of a Periodic Table of the Prime Numbers, which explores the categorization of the primes by their period length (and which I regrettably lack access to read). Hopefully, you find this literature useful.

For a crude attempt to describe the asymptotic of your sequence, the length of the period for prime $$p$$ can be shown to be at most $$p-1$$ (or otherwise a divisor of that), as in MSE Q3545702. So then, the sum of period lengths for primes up to $$n$$ has, in the worst case, the following upper bound.*

$$T(n)=\sum_{p\,\text{prime}\\p\le n} P(p) \le \sum_{p\,\text{prime}\\p\le n} (p-1) \sim \frac{n^2}{2\log n}$$

where the asymptotic to the sum is given by partial summation and the PNT, as in MO Q63412, and observing that the $$-1$$ term becomes $$\pi(n)\sim \frac{n}{\log n}$$ and vanishes.

* For convenience, I've recast your $$S(x)$$ (taken up to the index $$x$$ of the last included prime $$p_x$$) as $$T(n)$$ (taken up to an integer bound on the last included prime, $$n\ge p_x$$), so that we have $$\displaystyle T(p_x)=\sum_{p\,\text{prime}\\p\le p_x} P(p)=S(x)$$, and we should thus loosely expect $$T(x\log x)\approx S(x)$$ by the PNT. Then, the above worst case upper bound becomes $$S(x)\le\ldots\sim \frac{\left(x\log x\right)^{2}}{2\log\left(x\log x\right)}$$, which matches your $$0.94782x^{2.11976}$$ power approximation remarkably well (Desmos).

• Thank you for the contribution! With respect to the worst case upper bound, it is interesting to note that it is not extremely far from the actual $S(x)$ curve, since a great portion of primes will have a worst case period. From what I've calculated, it seems that it is more than a $1/3$. Commented Oct 26, 2022 at 1:15
• @ordptt: the proportion of primes for which $P(p) = p - 1$ is the subject of Artin's primitive root conjecture (en.wikipedia.org/wiki/Artin%27s_conjecture_on_primitive_roots) for $a = 10$; the conjecture provides an infinite product evaluating to this proportion which numerically is about $0.374 \dots$. The same heuristics that give that infinite product can be modified to give a heuristic answer to this question too but I haven't worked through the details yet. Commented Oct 26, 2022 at 2:47
• @QiaochuYuan This is extremely interesting! Is the value of the proportion $r_k$ of primes for which $P(p)=\frac{p-1}{k}$ known? That would probably be extremely helpful. See the comments of the question. Commented Oct 26, 2022 at 2:50
• @ordptt: this is the part I haven't worked out yet. Again it should follow from a generalization of the same heuristics that lead to Artin's conjecture. The idea is to assume that $10$ behaves like a randomly chosen element of the group of units $\bmod p$ so its order is the order of a random element of the cyclic group of order $p - 1$. I'll try to work out the details tomorrow but you can at least see a heuristic derivation of Artin's conjecture here: web.math.ucsb.edu/~agboola/teaching/2005/winter/old-115A/… Commented Oct 26, 2022 at 2:53
• @QiaochuYuan, I found this article on the subject: mast.queensu.ca/~murty/Franc-Murty.pdf. I don't understand much of it, but it gives an expression for $r_k$ for some kinds of $k$ Commented Oct 26, 2022 at 16:23

The value of $$P(p_n)$$ is always $$\frac{p_n-1}{k}$$ for some integer $$k$$. Then, the expected value of $$P(p_n)$$ is given by $$P(p_n)\sim\sum_{k=1}^{\infty}r_k\cdot\frac{p_n-1}{k}$$ Where $$r_k$$ is the proportion of primes that satisfy $$P(p_n)=\frac{p_n-1}{k}$$. Simplifying the expression gives $$P(p_n)\sim(p_n-1)\sum_{k=1}^{\infty}\frac{r_k}{k}$$ The values of $$r_k$$ seem to not be a solved problem in mathematics. There are some articles, such as this one, that address this subject. The first value, $$r_1$$, is known as Artin's Constant, and is about $$0.374$$. By numerically calculating, the value of the above sum appears to be $$0.577\pm0.001$$. These results match what @eyeballfrog pointed out in the comments.

With respect to the function $$S(x)$$, $$S(x)\sim\left(\sum_{k=1}^{\infty}\frac{r_k}{k}\right)\sum_{n=1}^{x}(p_n-1)$$ The above expression matches the calculated values remarkably well.

As also mentioned in Jam's answer, a rough approximation can be given by the Prime Number Theorem: $$S(x)\approx0.577\left(\frac{(x\ln(x))^2}{2\ln(x\ln(x))}-\frac{x}{\ln(x)}\right)$$ Though it seems that this is a really bad approximation. Replacing $$0.577$$ by $$\approx0.145$$ gives much better results

• @QiaochuYuan, what I meant is that using the PNT to derive an approximation to the sum of primes is also something that Jam did in his/her answer, which in their case was used to give an upper bound. Commented Oct 27, 2022 at 23:16
• Ah, okay. In that case I'm confused about where the loss of a factor of $3$ in accuracy comes from. Commented Oct 27, 2022 at 23:20
• @QiaochuYuan I believe it is purely due to error propagation. If you use better approximations, the difference from $0.577$ goes away, such as using the ones in these articles: emis.de/journals/JIS/VOL22/Axler/axler17.pdf (Corollary 5, Page 4) and arxiv.org/pdf/1011.1667.pdf (Eq. 16, Page 4) Commented Oct 27, 2022 at 23:25
• A least squares regression using the equation given in the second article gives 0.57651853 Commented Oct 27, 2022 at 23:52