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
- Count the number of words having sum of ASCII values less than and greater than k
- Largest number less than N with digit sum greater than the digit sum of N
- Multiplication table till N rows where every Kth row is table of K upto Kth term
- Numbers with prime frequencies greater than or equal to k
- Count of alphabets having ASCII value less than and greater than k
- Check whether all the rotations of a given number is greater than or equal to the given number or not
- Find the sum of prime numbers in the Kth array
- Prime Numbers present at Kth level of a Binary Tree
- Largest number less than N whose each digit is prime number
- Permutation of a string with maximum number of characters greater than its adjacent characters
- Number of elements greater than K in the range L to R using Fenwick Tree (Offline queries)
- Next greater number than N with exactly one bit different in binary representation of N
- Count number of substrings with numeric value greater than X
- Number of segments where all elements are greater than X
- Check if a number from every row can be selected such that xor of the numbers is greater than zero
- Maximize the number of indices such that element is greater than element to its left
- Sum of previous numbers that are greater than current number for given array
- Smallest number greater than n that can be represented as a sum of distinct power of k
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.