New update is available. Click here to update.
sidenav-btnClose
Topic list
Yogesh And Primes
MEDIUM
20 mins
347 upvotes
Other topics
Problem solved
Skill meter
Strings
-
Matrices (2D Arrays)
-
Sorting
-
Binary Search
-
Linked List
-
Stacks & Queues
-
Trees
-
Graph
-
Dynamic Programming
-
Greedy
-
Tries
-
Arrays
-
Binary Search Trees
-
Heap
-
Bit Manipulation
-

Yogesh And Primes

Medium
Avg time to solve 20 mins
Share
347 upvotes

Problem Statement

Yogesh is a very intelligent student and is interested in research in Machine Learning domain. His college has only one professor, Mr. Peter working in that field. He approaches the professor for the same, but professor wants to test him first.

To pass the test Yogesh must answer Q questions correctly. In all the Q questions, professor gives him three positive integers : A, B and K where A ≤ B.

Now Yogesh has to find an integer P such that it is closest to integer A and there are at least K prime numbers in range [A, P], where A <= P <= B.

Help Yogesh to find and print minimum possible P or print -1 if there no such possible integer.

Note: A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.

Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input :
5
2 5 1
2 5 2
4 12 2
3 17 7
5 5 1
Sample Output :
2
3
7
-1
5
Reset Code
Full screen
copy-code
Console