Yogesh And Primes
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.
Input format :
The first line of input contains one positive integer Q.
The following Q lines contains three spaced-separated integers A, B and K.
Output format :
For each query, print the answer in a new line, if it exists, else print −1.
Constraints:
1≤Q≤100,000
1≤A≤B≤1,000,000
1≤K≤1,000,000
A≤P≤B
Be the first one to answer
Add answer anonymously...
Top Capgemini Junior Analyst interview questions & answers
Popular interview questions of Junior Analyst
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app