Find the nearest prime number given a random number?

2007-04-06 7:39 pm
The question is:

If I have an integer N, can I find a prime number P which is nearest smaller/larger to N?

回答 (2)

2007-04-06 8:44 pm
✔ 最佳答案
The only way is by searching, but yuo can limit your search range by applying Bertrand's postulate :
for every n > 1 there is always at least one prime p such that n < p < 2n

Then you can search the range of [n/2, 2n] and find the prime out.

Another way to limit search is by approximation . From PNT, we have
nth prime number ~ nln(n)
then you can find k such that (k-1)ln(k) < n

2007-04-06 12:46:36 補充:
The last sentence is:then you can find k such that n within [ (k-1)ln(k), kln(k) ] and search the prime out
2007-04-06 8:32 pm
no you can not. it's because it's not an easy/fast way to find out the nth prime number.

if you know computer programming. you can use computer to find it out.
參考: me


收錄日期: 2021-04-23 16:53:20
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070406000051KK01070

檢視 Wayback Machine 備份