En matemáticas, el Postulado de Bertrand establece que hay un número primo en el rango donde n es un número natural y n >= 4. Chebyshev y luego Ramanujan lo demostraron. Una forma indulgente del postulado establece que existe un número primo en el rango de n a 2n para cualquier n(n >= 2).
Existe un primo p para para todo n <= 4. La forma menos estricta establece que existe un primo p. Para todo n <= 2.
Ejemplos:
Para n = 4 y 2*n – 2 = 6,
5 es un número primo en el rango (4, 6).
Para n = 5 y 2*n – 2 = 8,
7 es un número primo en el rango (5, 8).
Para n = 6 y 2*n – 2 = 10,
7 es un número primo en el rango (6, 10).
Para n = 7 y 2*n – 2 = 12,
11 es un número primo en el rango (7, 12).
Para n = 8 y 2*n – 2 = 14,
11 es un número primo en el rango (8, 14).
Ejemplos:
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 ?>
Javascript
<script> // Javascript code to verify Bertrand's // postulate for a given n. function isprime(n) { // check whether a number // is prime or not for (let i = 2; i * i <= n; i++) if (n % i == 0) // i is a factor of n return false; return true; } let n = 10; // Checking Bertrand's postulate // Presence of prime numbers in // range (n, 2n - 2) document.write( "Prime numbers in range (" + n + ", "+ (2 * n - 2) + ")" + "</br>" ); for (let i = n + 1; i < 2 * n - 2; i++) if (isprime(i)) document.write(i + "</br>"); </script>
Prime numbers in range (10, 18) 11 13 17
Publicación traducida automáticamente
Artículo escrito por jaideeppyne1997 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA