勒让德猜想的Java程序
它说在任何两个连续的自然数(n = 1, 2, 3, 4, 5, ...)平方之间总是有一个素数。这称为勒让德猜想。
猜想:猜想是基于不完整信息的命题或结论,尚未找到任何证据,即没有被证明或证伪。
Mathematically,
there is always one prime p in the range to where n is any natural number.
for examples-
2 and 3 are the primes in the range to .
5 and 7 are the primes in the range to .
11 and 13 are the primes in the range to .
17 and 19 are the primes in the range to .
例子:
Input : 4
output: Primes in the range 16 and 25 are:
17
19
23
解释:这里 4 2 = 16 和 5 2 = 25
因此,16 到 25 之间的素数是 17、19 和 23。
Input : 10
Output: Primes in the range 100 and 121 are:
101
103
107
109
113
// Java program to verify Legendre\'s Conjecture
// for a given n.
class GFG {
// prime checking
static boolean isprime(int n)
{
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
static void LegendreConjecture(int n)
{
System.out.println("Primes in the range "+n*n
+" and "+(n+1)*(n+1)
+" are:");
for (int i = n*n; i <= ((n+1)*(n+1)); i++)
{
// searching for primes
if (isprime(i))
System.out.println(i);
}
}
// Driver program
public static void main(String[] args)
{
int n = 50;
LegendreConjecture(n);
}
}
//This code is contributed by
//Smitha Dinesh Semwal
详情请参阅勒让德猜想的完整文章!