Breaking Primes
Practice
4 (500 votes)
Mathematics
Sieve
Easy Medium
Binary search algorithm
Mathematics
Mathamatics
Problem
64% Success 5386 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Jesse Pinkman loves Maths. He loves prime numbers and wants to research on this topic. He asks his Maths professor Walter White a.k.a. Heisenberg for guidance. Heisenberg says that he will guide him if and only if he answers all his Q questions correctly. In all the Q questions, he gives three positive integers A, B and K where \(A ≤ B.\)

He asks Jesse to find an integer P closest to A such that there are at least K prime numbers in the range \([A, P]\) where \(A ≤ P ≤ B \). Jesse needs your help as he is very interested to do research under Heisenberg. Find the minimum P or report 1 if there is no such P which meets the constraints.

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\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
78 votes
Tags:
Ad-HocMathematicsOpenApprovedEasy-MediumMathamatics
Points:30
5 votes
Tags:
MathematicsBasic MathMath
Points:30
77 votes
Tags:
MathematicsOpenApprovedEasy-MediumMathamatics