Is it possible to express the $n$-th composite as a direct formula involving the $n$-th prime $p(n)$, and/or the prime counting function $\pi(n)$?

127 Views Asked by At

Is it possible to express the $n$-th composite integer (or $n$-th odd composite integer) as a direct formula involving the $n$-th prime $p(n)$, and/or the prime counting function $\pi(n)$ ?

1

There are 1 best solutions below

5
On BEST ANSWER

Let $c\left(n\right)$ denote the $n$-th composite integer.

There is exactly $n$ composites and $\pi\left(c\left(n\right)\right)$ primes less than or equal to $c\left(n\right)$, so:

$$c\left(n\right)=n+\pi\left(c\left(n\right)\right)$$

We also know that $n<c\left(n\right)$, therefore:

$$c\left(n\right)\geq n+\pi\left(n\right)$$

If we repeat the same logic, we also know that:

$$c\left(n\right)\geq n+\pi\left(_{n+\pi\left(n\right)}\right)\geq n+\pi\left(n\right) $$ $$ c\left(n\right)\geq n+\pi\left(_{n+\pi\left(_{n+\pi\left(n\right)}\right)}\right)\geq n+\pi\left(_{n+\pi\left(n\right)}\right)\geq n+\pi\left(n\right) $$ And so on: $$ c\left(n\right)=n+\pi_{\left(n+\pi_{\left(n+\pi_{\left(n+\pi_{\left(\ldots\right)}\right)}\right)}\right)} $$

Although this is a recursive function, the number of iterations needed to find $c\left(n\right)$ is really small. For example, this one works for all $n\leq10^{10}$: $$ c\left(n\right)=n+\pi\left(n+\pi\left(n+\pi\left(n+\pi\left(n+\pi\left(n+\pi\left(n\right)\right)\right)\right)\right)\right) $$

Using the same method, we can also find the $n$-th odd composite, which is:

$$ c_{odd}\left(n\right)=2n+2\pi_{\left(2n+2\pi_{\left(2n+2\pi_{\left(2n+2\pi_{\left(\ldots\right)}\right)}\right)}\right)}-1 $$



Example with $c(123456)$:

$$ 123456+\pi\left(123456\right)=135057 $$ $$ 123456+\pi\left(135057\right)=136038 $$ $$ 123456+\pi\left(136038\right)=136124 $$ $$ 123456+\pi\left(136124\right)=136131 $$ $$ 123456+\pi\left(136131\right)=136131 $$ $$ 123456+\pi\left(136131\right)=136131 $$ $$ \ldots $$ $$ c\left(123456\right)=136131 $$



Pseudo-code:

function nth_composite(n){
    c = n;
    while(c != n+pi(c)){
        c = n+pi(c);
    } 
    return c;
}



Test results:

n                   c(n)                Iterations needed

10                  16                  2         
100                 132                 4         
1000                1196                4         
10000               11373               4         
100000              110486              4         
1000000             1084604             5
10000000            10708554            6
100000000           106091744           6
1000000000          1053422338          6
10000000000         10475688326         7
100000000000        104287176418        7