Yogesh And Primes Problem Statement

Yogesh, a bright student interested in Machine Learning research, must pass a test set by Professor Peter. To do so, Yogesh must correctly answer Q questions where each question provides three positive integers: A, B, and K, with the condition A ≤ B.

Yogesh needs to find an integer P such that P is as close as possible to A and there are at least K prime numbers in the range [A, P], where A ≤ P ≤ B.

Please find and print the minimum possible P or print -1 if no such integer exists.

Example:

Input:
The first line of input contains one positive integer Q.
The following Q lines contain three space-separated integers A, B, and K.
Output:
Print the answer for each query on a new line, or -1 if not possible.

Constraints:

  • 1≤Q≤100,000
  • 1≤A≤B≤1,000,000
  • 1≤K≤1,000,000
  • A≤P≤B
AnswerBot
4mo

Yogesh needs to find the minimum possible integer P such that there are at least K prime numbers in the range [A, P].

  • Iterate from A to B and check if each number is prime

  • Keep track of the count of pri...read more

Help your peers!
Select
Add answer anonymously...
Junior Analyst Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits