how to generate next prime number for a given long interger n where n can be 0<=n<=10^18
for example if n is 10 then the next prime number is 11. how can i do it in 0.5 sec?? is there any number theory? pls give me any suggestion..
thanks in advance..
http://en.wikipedia.org/wiki/Prime_gap, so simple bruteforce is fast( of course, you need a reasonable primality test).
How to check prime ????? sqrt(10^18) = 10^9
http://help.topcoder.com/data-science/competing-in-algorithm-challenges/algorithm-tutorials/primality-testing-non-deterministic-algorithms/, there are some non-deterministic methods that work very well with this limit(10^18).
after reading the topcoder tutorial & wiki link, i implement in this way..my code is it okay??
http://www.wikihow.com/Check-if-a-Number-Is-Prime