Given a number N, the task is to print the Kth prime number greater than N.
Note: N and K are so given such that answer is always less than 10^6.
Input: N = 5, K = 5 Output: 19 Input: N = 10, K = 3 Output: 17
A simple solution for this problem is to iterate from n+1 to 10^6 and for every number, check if it is prime and print the Kth prime number. This solution looks fine if there is only one query. But not efficient if there are multiple queries.
An efficient solution for this problem is to generate all primes less than 10^6 using Sieve of Eratosthenes and iterate from n+1 to 10^6 and then print the Kth prime number.
- Smallest Special Prime which is greater than or equal to a given number
- Largest number not greater than N which can become prime after rearranging its digits
- Numbers with prime frequencies greater than or equal to k
- Print the nearest prime number formed by adding prime numbers to N
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Check if a prime number can be expressed as sum of two Prime Numbers
- Find coordinates of a prime number in a Prime Spiral
- Check whether all the rotations of a given number is greater than or equal to the given number or not
- Puzzle | Number of Sheets to be turned so that Prime Number has a Vowel on the other side
- Number which has the maximum number of distinct prime factors in the range M to N
- Find the minimum number to be added to N to make it a prime number
- Count of prime digits of a Number which divides the number
- Represent a number as a sum of maximum possible number of Prime Numbers
- Least Greater number with same digit sum
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.