![]() |
It says that there is always one prime number between any two consecutive natural number\’s(n = 1, 2, 3, 4, 5, …) square. This is called Legendre’s Conjecture. Conjecture: A conjecture is a proposition or conclusion based upon incomplete information to which no proof has been found i.e it has not been proved or disproved.
Examples: Input : 4 Explanation: Here 42 = 16 and 52 = 25 Hence, prime numbers between 16 and 25 are 17, 19 and 23. Input : 10 Python3
Output : Primes in the range 2500 and 2601 are: Time Complexity: O(n*sqrtn). isPrime() function takes O(n) time and it is embedded in LegendreConjecture() function which also takes O(n) time as it has loop which starts from n2 and ends at Auxiliary Space: O(1) METHOD 2:Instead of iterating through a range of numbers to check for prime numbers, the new approach uses the sympy library to generate all prime numbers in a given range.
Python3
Output : Primes in the range 2500 and 2601 are: Time complexity: O(n log log n), as the sieve of Eratosthenes algorithm has a time complexity of O(n log log n) for finding all primes up to n, and the algorithm used here is a modified version of the sieve of Eratosthenes. Auxiliary Space: O(n), because the algorithm uses a boolean list of size n+1 to keep track of whether each number is prime or not. Please refer complete article on Legendre’s Conjecture for more details! |
Reffered: https://www.geeksforgeeks.org
Python Programs |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |