📜  勒让德的猜想

📅  最后修改于: 2021-04-23 19:58:12             🧑  作者: Mango

它说在任何两个连续的自然数(n = 1,2,3,4,5,…)平方之间总是存在一个质数。这称为勒让德猜想。

猜想:猜想是基于不完整信息的命题或结论,该信息未找到证据,即尚未被证明或被证明。

例子:

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
 
C++
// C++ program to verify Legendre's Conjecture
// for a given n.
#include 
using namespace std;
 
// prime checking
bool isprime(int n)
{
    for (int i = 2; i * i <= n; i++)
        if (n % i == 0)
            return false;
    return true;
}
 
void LegendreConjecture(int n)
{
   cout << "Primes in the range "<


Java
// 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


Python3
# Python3 program to verify Legendre's Conjecture
# for a given n
 
import math
 
def isprime( n ):
     
    i = 2
    for i in range (2, int((math.sqrt(n)+1))):
        if n%i == 0:
            return False
    return True
     
def LegendreConjecture( n ):
    print ( "Primes in the range ", n*n
            , " and ", (n+1)*(n+1)
            , " are:" )
             
     
    for i in range (n*n, (((n+1)*(n+1))+1)):
        if(isprime(i)):
            print (i)
             
n = 50
LegendreConjecture(n)
 
# Contributed by _omg


C#
// C# program to verify Legendre's
// Conjecture for a given n.
using System;
 
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)
    {
        Console.WriteLine("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))
                Console.WriteLine(i);
        }
    }
     
    // Driver program
    public static void Main(String[] args)
    {
        int n = 50;
         
        LegendreConjecture(n);
    }
}
 
// This code is contributed by parashar.


PHP


Javascript


输出 :

Primes in the range 2500 and 2601 are:
2503
2521
2531
2539
2543
2549
2551
2557
2579
2591
2593