Bertrand’s Postulate
In mathematics, Bertrand’s Postulate states that there is a prime number in the range
to
where n is a natural number and n >= 4. It has been proved by Chebyshev and later by Ramanujan. A lenient form of the postulate states that there exists a prime in range n to 2n for any n(n >= 2).
There exists a prime p for
for all n <= 4. The less stricter form states that there exists a prime p. For
for all n <= 2.
Examples:
For n = 4 and 2*n – 2 = 6,
5 is a prime number in the range (4, 6).
For n = 5 and 2*n – 2 = 8,
7 is a prime number in the range (5, 8).For n = 6 and 2*n – 2 = 10,
7 is a prime number in the range (6, 10).For n = 7 and 2*n – 2 = 12,
11 is a prime number in the range (7, 12).For n = 8 and 2*n – 2 = 14,
11 is a prime number in the range (8, 14).
Examples :
Input: n = 4
Output: Prime numbers in range (4, 6)
5
Input: n = 5
Output: Prime numbers in range (5, 8)
7
Input: n = 6
Output: Prime numbers in range (6, 10)
7
C++
// CPP code to verify Bertrand's postulate // for a given n. #include <bits/stdc++.h> using namespace std; bool isprime(int n) { // check whether a number is prime or not for (int i = 2; i * i <= n; i++) if (n % i == 0) // i is a factor of n return false; return true; } int main() { int n = 10; // Checking Bertrand's postulate // Presence of prime numbers in range (n, 2n - 2) cout << "Prime numbers in range (" << n << ", " << 2 * n - 2 << ")\n"; for (int i = n + 1; i < 2 * n - 2; i++) if (isprime(i)) cout << i << "\n"; return 0; } |
Java
// Java code to verify Bertrand's // postulate for a given n. import java.io.*; class GFG { static boolean isprime(int n) { // check whether a number // is prime or not for (int i = 2; i * i <= n; i++) if (n % i == 0) // i is a factor of n return false; return true; } // Driver Code public static void main (String[] args) { int n = 10; // Checking Bertrand's postulate // Presence of prime numbers in // range (n, 2n - 2) System.out.println("Prime numbers in range (" + n + ", "+ (2 * n - 2) + ")"); for (int i = n + 1; i < 2 * n - 2; i++) if (isprime(i)) System.out.println(i); } } // This code is contributed // by shiv_bhakt |
Python3
# PHP code to verify # Bertrand's postulate # for a given n. def isprime(n): # check whether a number # is prime or not i = 2; while(i * i <= n): if (n % i == 0): # i is a factor of n return False; i = i + 1; return True; # Driver Code n = 10; # Checking Bertrand's # postulate Presence # of prime numbers in # range (n, 2n - 2) print("Prime numbers in range (" , n , ", ", 2 * n - 2 , ")"); i = n + 1; while(i < (2 * n - 2)): if (isprime(i)): print(i); i = i + 1; # This code is contributed by mits |
C#
// C# code to verify Bertrand's // postulate for a given n. using System; class GFG { static bool isprime(int n) { // check whether a number // is prime or not for (int i = 2; i * i <= n; i++) if (n % i == 0) // i is a factor of n return false; return true; } // Driver Code public static void Main () { int n = 10; // Checking Bertrand's postulate // Presence of prime numbers in // range (n, 2n - 2) Console.WriteLine("Prime numbers in range (" + n + ", "+ (2 * n - 2) + ")"); for (int i = n + 1; i < 2 * n - 2; i++) if (isprime(i)) Console.WriteLine(i); } } // This code is contributed // by shiv_bhakt |
PHP
<?php // PHP code to verify Bertrand's // postulate for a given n. function isprime($n) { // check whether a number // is prime or not for ($i = 2; $i * $i <= $n; $i++) if ($n % $i == 0) // i is a factor of n return false; return true; } // Driver Code $n = 10; // Checking Bertrand's postulate // Presence of prime numbers in // range (n, 2n - 2) echo "Prime numbers in range (" , $n , ", ", 2 * $n - 2 , ")\n"; for ($i = $n + 1; $i < 2 * $n - 2; $i++) if (isprime($i)) echo $i , "\n"; // This code is contributed by ajit ?> |
Prime numbers in range (10, 18) 11 13 17
Recommended Posts:
- Number of K length subsequences with minimum sum
- Check whether the given integers a, b, c and d are in proportion
- Count of matchsticks required to represent the given number
- Count number of ways to arrange first N numbers
- Probability that a random pair chosen from an array (a[i], a[j]) has the maximum sum
- Number of triangles that can be formed
- Find the deleted value from the array when average of original elements is given
- Count of N-digit numbers with all distinct digits
- Sort the numbers according to their product of digits
- Kth number from the set of multiples of numbers A, B and C
- Find the previous fibonacci number
- Find the quadratic equation from the given roots
- Smallest N digit number which is a perfect fourth power
- Angle subtended by an arc at the centre of a circle
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



