Given a number n, the task is to find two consecutive prime such that the product of these two prime is greater than or equal to n.
Output: 3 5
Explanation: 3 and 5 are consecutive prime numbers whose product is greater than 14.
Suppose n is of the range 10^8 to 10^10. We cannot find out primes using sieve because the range is upto10^10.
We can find the required consecutive primes by doing the following method.
- Find the greatest prime which is less than sqrt(n) and store it in a temporary variable (first).
- Find the smallest prime which is greater than sqrt(n) and store it in a temporary variable(second).
- If the product of first and second is greater than equal to n then print it.
- Else find a prime just greater than second and print it along with second.
Time Complexity: O(sqrt(n))