This is somewhat interesting. I was trying to do a demo to abort a hopeless computation, so I decided to ask Mathematica for the ten trillionth prime. To be honest, I just typed Prime[1]
and arbitrarily added some zeros. I was surprised to see the output in a few seconds. I was even more surprised to see that Mathematica has a significantly more difficult time to compute the five trillionth prime, or primes with other less "nice" order numbers.
In[1]:= Timing[Prime[10000000000000]]
Out[1]= {2.45313, 323780508946331}
In[2]:= Timing[Prime[5000000000000]]
Out[2]= {94.625, 158308642985671}
In[3]:= Timing[Prime[5234000000879]]
Out[3]= {78.5469, 165964973818549}
So naturally I have two questions:
- What's the reason behind the timing difference?
- How does Mathematica find the n-th prime in general?