# What is notable about the composite numbers between twin primes?

Look at the composites between twin primes (A014574):

$$4, 6, 12, 18, 30, 42, 60, 72, 102, 108, 138, 150, 180, 192, 198, 228, \\ 240, 270, 282, 312, 348, 420, 432, 462, 522, 570, 600, 618, \ldots \;.$$

Is there anything special about their distribution of factors, number of divisors, or other number-theoretical properties? Or are these twin-prime averages totally "normal" numbers, as far as we know?

• Just my grain of salt. I'd reckon that if $n$ has many prime factors, it'd be "more likely" that $n-1$, $n+1$ were primes. I have no idea if anybody has managed to put the converse of that into a precise result, though. Dec 29, 2019 at 1:37
• @RhysHughes: what about $192, 198$? Dec 29, 2019 at 1:55
• but I wonder if there are infinitely many primes $p$ such that $p+2, p+6,$ and $p+8$ are also prime Dec 29, 2019 at 1:59
• @RhysHughes: also $102,108$ Dec 29, 2019 at 2:06
• except for $4$, they're all divisible by $6$ Dec 29, 2019 at 2:10

This answer is analogous to my answer to Why do even numbers which surround primes have more divisors than those which surround composites?. In order to make it self-contained, I'll repeat some things that I wrote there. I'll derive the expected (additive) excess of distinct prime factors and the expected (multiplicative) excess of divisors of a large even number between twin primes.

On the random model of the primes, the probability for an even number $$n$$ to be divisible by an odd prime $$p$$ is a priori $$\frac1p$$. If we know that $$n$$ is adjacent to two primes $$q$$, $$q+2$$, this is increased to $$\frac1{p-2}$$, since we know that $$q$$ and $$q+2$$ are not divisible by $$p$$, which excludes two of the non-zero values of $$n\bmod p$$.

The expected number of distinct prime factors of an even number $$n$$ is roughly

$$1+\sum_{3\le p\le n^r}\frac1p\;,$$

where $$r=\mathrm e^\gamma$$ (see Asymptotic distance between $x^2+1$ primes?). Conditional on $$n$$ being between twin primes $$q$$, $$q+2$$ this becomes

$$\begin{eqnarray} 1+\sum_{3\le p\le n^r}\frac1{p-2} &=& 1+\sum_{3\le p\le n^r}\frac1p+\sum_{3\le p\le n^r}\left(\frac1{p-2}-\frac1p\right) \\ &=& 1+\sum_{3\le p\le n^r}\frac1p+\sum_{3\le p\le n^r}\frac2{p(p-2)} \\ &\approx& 1+\sum_{3\le p\le n^r}\frac1p+\sum_{3\le p}\frac2{p(p-2)} \;, \end{eqnarray}$$

where we can remove the upper limit on the right-hand sum for large $$n$$ since this series converges (whereas the sum over $$\frac1p$$ diverges). To improve convergence, we can write

$$\begin{eqnarray} \sum_{3\le p}\frac2{p(p-2)} &=& 2\sum_{3\le p}\left(\frac1{p^2}+\frac2{p^2(p-2)}\right) \\ &=& 2\left(P(2)-\frac14+2\sum_{3\le p}\frac1{p^2(p-2)}\right)\;, \end{eqnarray}$$

where $$P(s)$$ is the Prime zeta function. We have $$P(2)\approx0.452247$$, and Wolfram|Alpha evaluates the right-hand series to approximately $$0.130647$$, so the excess in the number of distinct prime factors of a large even number between twin primes comes out as approximately $$0.927084$$, almost a whole prime factor, and more than three times the excess for large even numbers adjacent to a prime.

We can perform a similar analysis to find the (in this case multiplicative) excess of divisors for even numbers between twin primes. A number with prime factorization $$\prod_ip_i^{k_i}$$ has $$\prod_i(k_i+1)$$ divisors, so the logarithm of the number of divisors is $$\sum_i\log(k_i+1)$$.

For a given odd prime $$p$$, a priori an even number $$n$$ has probability $$\frac{p-1}p$$ of containing $$0$$ factors of $$p$$, probability $$\frac1p\cdot\frac{p-1}p$$ of containing $$1$$ factor of $$p$$, and generally probability $$\frac1{p^k}\frac{p-1}p$$ of containing $$k$$ factors of $$p$$. Conditional on $$n$$ being between twin primes, it has probability $$\frac{p-3}{p-2}$$ of containing no factors of $$p$$, probability $$\frac1{p-2}\frac{p-1}p$$ of containing $$1$$ factor of $$p$$, and generally probability $$\frac{p-1}{p-2}\frac1{p^k}$$ of containing $$k\gt0$$ factors of $$p$$.

Thus the expected excess in the logarithm of the number of divisors given that $$n$$ is between twin primes is

$$\begin{eqnarray} \sum_{3\le p}\sum_{k=0}^\infty\frac{\log(k+1)}{p^k}\left(\frac{p-1}{p-2}-\frac{p-1}p\right) &=& 2\sum_{3\le p}\sum_{k=0}^\infty\frac{\log(k+1)}{p^{k+1}}\frac{p-1}{p-2} \\ &=& 2\sum_{3\le p}\sum_{k=2}^\infty\frac{\log k}{p^k}\frac{p-1}{p-2}\;. \end{eqnarray}$$

I don't see a way to rewrite this as a single sum. To improve the convergence of the double sum, we can rewrite it like this:

$$\begin{eqnarray*} 2\sum_{3\le p}\sum_{k=2}^\infty\frac{\log k}{p^k}\frac{p-1}{p-2} &=& 2\sum_{3\le p}\sum_{k=2}^\infty\left(\frac{\log k}{p^k}+\frac{\log k}{p^k}\frac1{p-2}\right) \\ &=& 2\left(\sum_{k=2}^\infty\left(P(k)-2^{-k}\right)\log k+\sum_{3\le p}\sum_{k=2}^\infty\frac{\log k}{p^k}\frac1{p-2}\right)\;. \end{eqnarray*}$$

The single sum in the first term is the one that occurred for even numbers adjacent to a single prime (see the link above); it evaluates to approximately $$0.226201$$. The terms of the double sum now decrease as $$p^{-3}$$, and it evaluates to approximately $$0.163679$$ (Wolfram|Alpha computation). The overall sum is thus approximately $$0.779761$$, so a large even number between twin primes is expected to have approximately $$\mathrm e^{0.779761}\approx2.180950$$ times as many divisors as usual, a substantially greater effect than for even numbers adjacent to a prime. (Note that this is the geometric mean, since we used the expected value of the logarithm; if you average the divisor counts themselves, you'll get a slightly higher result, since the geometric mean is less than the arithmetic mean.)

P.S.:

Here's some numerical evidence that these calculations are correct. The plot shows the excesses over the average for even numbers between twin primes, averaged up to $$10^k$$ with $$k=3,\cdots,8$$ ($$k$$ is marked on the $$x$$ axis). The additive excess in distinct prime factors is shown with red crosses; the red line shows the calculated limit. The logarithmic excess in divisors is shown with blue crosses; the blue line shows the calculated limit. The values are far from converged but are entirely compatible with the calculated limits. Here's the code I used to generate the data.

P.P.S.:

In this answer, Nilotpal Kanti Sinha provides numerical data for the excesses of numbers between twin primes over numbers on either side of twin primes. We can apply the present analysis also to the numbers on either side of twin primes. For $$p\ge5$$, the analysis remains the same, as two non-zero residues are excluded for each $$p\ge5$$. However, for $$p=3$$, the effect is reversed. Whereas a number between twin primes is always divisible by $$3$$ (which accounts for $$\frac23$$ of the $$0.927$$ excess distinct prime factors, since an arbitrary number only has probability $$\frac13$$ of being divisible by $$3$$), a number on either side of twin primes is never divisible by $$3$$. Since the contributions from $$p\ge5$$ are the same, the excess in distinct prime factors of numbers between twin primes over numbers on either side of twin primes is exactly $$1$$. (This can't be compared to Nilotpal Kanti Sinha's results, since they are expressed multiplicatively, and in the case of the number of distinct prime factors the multiplicative excess vanishes in the limit, since the additive excess converges and the expected number of distinct prime factors diverges.)

For the expected number of divisors, we likewise need to remove the term for $$p=3$$ from the sum. This is

$$2\sum_{k=1}^\infty\frac{\log(k+1)}{3^k}\approx0.871677\;.$$

This logarithmic excess leads to a multiplicative excess of approximately $$\mathrm e^{0.871677}\approx2.390917$$ in the number of divisors of numbers between twin primes over numbers on either side of twin primes, in rough agreement with Nilotpal Kanti Sinha's results. As can be seen from the diagram above, better agreement is not to be expected for data accessible to quick computer searches.

• This is an impressive analysis, and an interesting conclusion: even numbers between twin primes have twice as many divisors as usual. This is along the lines of @Nilotpal's answer. Dec 31, 2019 at 1:15
• @JosephO'Rourke: Thanks. The comparison in Nilotpal Kanti Sinha's answer is actually not to the average but to the numbers on either side of twin primes. It turns out that the excesses are roughly similar to the excesses over the average, though, which means that for numbers on either side of twin primes the negative effect for $p=3$ roughly cancels the positive effect for $p\ge5$. I've added an analysis of this case to my answer. Dec 31, 2019 at 2:02
• I find this question and all the analysis in its solution very interesting. Until yesterday, I would not have expected the even numbers between twin primes to have twice as many divisors as other even numbers. To me the key learning was that although the standard model is primes is well know, it can have consequences which are not immediately obvious and we may never find these interesting properties if we stopped at the standard model instead of exploring its consequences. Dec 31, 2019 at 5:27
• This answer could make a nice, short paper. Dec 31, 2019 at 12:18

Yes there is something interesting about the composite number between twin primes. Let $$p,p+2$$ be a twin prime pair. Then $$p-1$$ is the composite number just preceding the pair, $$p+1$$ is the composite number between the pair and $$p+3$$ is the composite number just after the pair. Let $$d(n)$$ and $$\omega(n)$$ be the number of divisors and the number of distinct prime factors of $$n$$ respectively. Then, experimental data shows that

$$2.27 \sum_{p,p+2 \in P}{d(p-1)} \approx 2.27 \sum_{p,p+2 \in P}{d(p+3)} \approx \sum_{p,p+2 \in P}{d(p+1)}$$

$$1.24 \sum_{p,p+2 \in P}{\omega(p-1)} \approx 1.24 \sum_{p,p+2 \in P}{\omega(p+3)} \approx \sum_{p,p+2 \in P}{\omega(p+1)}$$

i.e. roughly speaking, the composite number between a twin prime pair has on an average $$24\%$$ more distinct prime factors than the composite number just before or just after the pair and more than twice as many divisors.

• Why does the middle composite have significantly more divisors and prime factors than its composite neighbors?
• Why does the just composite before a twin prime have roughly the same number of divisors or prime factors as the composite just after the twin prime?

I shall post this in a separate question with the detailed data not only for twin prime but similar observations for other prime gaps.

• Nice, but isn't this simply because twin primes are of form $3k-1,3k+1$, hence the composite in between them is always divisible by $3$, which cannot be said about the sourrounding $3k-2$ and $3k+2$? You might want to check behavior of $3k-2$, $3k$ and $3k+2$ for generic integer $k$.
– Sil
Dec 30, 2019 at 5:53
• @Sil This looks like a generic behavior. Numbers that are equidistant from the middle of a prime gap of a fixed width have roughly the same number of divisors and distinct prime factors. I am drafting a post with these observations. Dec 30, 2019 at 5:57
• Well you can craft that pattern without primes as well, take for example $3k-4,3k,3k+4$, same behavior. I am afraid this has nothing to do with primes specifically, but looking forward to the post.
– Sil
Dec 30, 2019 at 6:00
• @Sil Yes, I suspect so. But what I observed is that the key difference in the multiplier. For primes as in mentioned in the above post, the is about $1.24$ but for and arbitrary series of the form $6k \pm 1$, it is about $1.27$ but I need to run it for larger number to see if they actually converge to the same value. Dec 30, 2019 at 6:11
• Well there is much more numbers of form $6k \pm 1$ than primes, so that is only approximately comparable.
– Sil
Dec 30, 2019 at 6:23

Other than $$n=4$$, $$n$$ has the property that for every prime number $$q=6k\pm 1$$, $$\frac{n}{6}\not \equiv \pm k \bmod q$$.

Let $$m:=\frac{n}{6};\ 6m=n$$ and the twin primes $$(n-1),(n+1)$$ are represented as $$(6m-1),(6m+1)$$

We see from the properties of the semiprime $$(6m-1)(6m+1)=36m^2-1$$. If $$36m^2-1$$ is not a semiprime, it is divisible by some prime $$6k\pm 1,\ k\ne m$$. In other words $$36m^2-1=(6k\pm 1)(6j\pm 1)$$ where $$k,j\ne m$$. Expanding, $$36m^2-1=36jk\pm 6j \pm 6k-1$$ which reduces to $$6m^2=6jk\pm j \pm k$$

This means $$m^2=jk \pm \frac{j\pm k}{6}$$, and since $$m^2$$ is an integer, $$\frac{j\pm k}{6}$$ must be an integer, call it $$r$$. So $$j=6r\pm k$$ and we can substitute this back to obtain $$m^2=(6r\pm k)k \pm r=k^2\pm r(6k\pm 1)$$.

Finally we obtain $$m^2-k^2=(m-k)(m+k)=r(6k\pm 1)$$. This means that $$(m-k)(m+k)\equiv 0 \bmod q$$ which can only be true if $$m\equiv \pm k \bmod q$$.

So if $$36m^2-1$$ is not a semiprime, then $$m\equiv \pm k \bmod q$$ when $$q\mid 36m^2-1$$. But if $$(6m-1),(6m+1)\in \mathbb P$$ then $$36m^2-1$$ is a semiprime, so for every prime number $$q=6k\pm 1$$, $$m\not \equiv \pm k \bmod q \Rightarrow \frac{n}{6}\not \equiv k \bmod q$$.

• You are saying that if $6n+1,6n-1$ are both primes and $k<n$ then $6n \not \equiv \pm 6k \bmod 6k \pm 1$... Dec 29, 2019 at 5:07
• @reuns Apologies for a very late night entry; I have corrected it to clarify my conflation of OP's variable $n$ and my variable, which I have now named $m$. What I am saying is that if $6m-1$ and $6m+1$ are both primes and $k< m$ then $\frac{n}{6}=m \not \equiv \pm k \bmod (6k\pm 1)$. Dec 30, 2019 at 2:20

$$n-1,n+1$$ are both primes iff for all prime $$p\le \sqrt{n}, n \not \equiv \pm 1\bmod p$$.

The random model for the primes, from which we predict the density of twin primes, is that those conditions are more or less independent from one $$p$$ to the other, ie. $$n$$ has nothing else special.

• We use the random model for the primes for specific types of questions about them, for which we do not think there should be any difference between primes and any other sequence with the same asymptotic density. I don’t think that you can apply such model here without a bit more justification. Dec 29, 2019 at 5:09
• No idea of what you mean with "justification". If you don't believe in the random model then do you believe in the twin prime conjecture and its conjectured asymptotic ? If not you should explain why the numerical experiments are so close to the predictions. Dec 29, 2019 at 5:15
• What I mean is: not all properties of the primes behave like the random model would predict. To give an obvious example, the average amount of divisors of the first elements in a “random” sequence of integers almost surely diverges, but of course this isn’t true for primes. You need to argue (if even just a bit) that the random model applies here. Dec 29, 2019 at 5:19
• Can you repeat your obvious example. The random model applies when we are taking a formula which isn't based on the primes, for example a formula based on a system of polynomial formulas. The "main" conjecture is that it is impossible to create something correlated with the primes without explicitly mentioning the primes. For example $\sum_n e^{ian} n^{-s}$ and $\sum_p e^{iap}p^{-s}\log p$ behave quite the same way : the complex exponentials aren't correlated to the primes. Dec 29, 2019 at 5:22
• The problem with this answer is not so much that the application of the random model needs to be justified, but that you didn't actually apply it (see my answer). Dec 31, 2019 at 6:55