restart.'s blog

By restart., 10 years ago, In English

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..

  • Vote: I like it
  • +4
  • Vote: I do not like it

»
10 years ago, # |
Rev. 2   Vote: I like it +14 Vote: I do not like it

http://en.wikipedia.org/wiki/Prime_gap, so simple bruteforce is fast( of course, you need a reasonable primality test).