Method
There are $44$ Mersenne primes implemented in Mathematica. Their exponents are instantly returned with (the few more tentative ones can be added to this list manually)
exp = MersennePrimeExponent @ Range @ 44
{2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279, 2203,
2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209,
44497, 86243, 110503, 132049, 216091, 756839, 859433, 1257787,
1398269, 2976221, 3021377, 6972593, 13466917, 20996011, 24036583,
25964951, 30402457, 32582657}
Mersenne primes are of the form $2^n-1$; one could compute them all with 2^exp-1
, but the 44th Mersenne prime has nearly 10 million digits, so I don't recommend it (MMA can handle their display, though). Nevertheless, because they are of the form $2^n-1$, which is a monotonic function, it is sufficient to translate x
- i.e., the input smaller of which you want to find the number of primes - to Log2[x + 1]
.
Function
One can make a function:
f[x_] := Count[exp, u_ /; u < Log2[x + 1]]
Then:
f[2]
0
f[3]
0
f[10]
2
f[100]
3
f[100000]
5
f[131071]
5
f[131072]
6
and for example
f[123456789987623456789876523456785432123456789]
12
Plotting
plot1 = LogLinearPlot[f[x], {x, 1, 10^20}, Frame -> True, PlotRange -> Full];
plot2 = LogLinearPlot[f[x], {x, 1, 10^300}, Frame -> True, PlotRange -> Full];
GraphicsRow[{plot1, plot2}, ImageSize -> 800]
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/4ENPQ.png)
The horizontal axis displays the exponent for the prime in Log10
basis. MMA is not able to go higher than the range showed in plot2
. Note that, as mentioned,
Log10[2^Last[N @ exp]]
9.80835709543099*10^6
meaning that the 44th Mersenne prime has almost 10 million digits, being ridiculously big.
PrimeQ
, or inMersennePrimeExponentQ
from the documentation. $\endgroup$Count
where the first argument toCount
isRange[ ...something... ]
and the second argument usesMersennePrimeExponentQ
. $\endgroup$