算法找到比最大素数小x [英] Algorithm to find largest prime number smaller than x
本文介绍了算法找到比最大素数小x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何计算最大素数小于值x?
How do I calculate the largest prime number smaller than value x?
在实际事实上,它不必是精确的,只是近似的,靠近到x
In actual fact, it doesn't have to be exact, just approximate and close to x.
x是一个32位的整数。
x is a 32 bit integer.
的想法是,x是配置参数。我使用的最大素数小于X(称之为Y)作为参数传递给类构造函数。 y值必须是一个素数。
The idea is that x is a configuration parameter. I'm using the largest prime number less than x (call it y) as the parameter to a class constructor. The value y must be a prime number.
推荐答案
一些好的信息这里一>上的功能圆周率(x)的。显然,
Some good info here on the function pi(x). Apparently,
pi(x) = the number of primes less than x
和可以近似PI(X)与
and you can approximate pi(x) with
x/(log x - 1)
而
the n-th prime of that list of primes is equal to approximately n(log n)
这篇关于算法找到比最大素数小x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文