Smallest Prime Factor
Time limit1sMemory limit128 MB
Given N and prime P, find the N-th positive integer whose smallest prime factor equals P, or print 0 if it exceeds 10^9.
- Level
Medium6 of 10
- Topics
- Number theory, Math, Binary search
- Solved
- No attempts yet
Problem
List the positive integers whose smallest prime factor is P in increasing order. Find the N-th number in this list.
Input
The first line contains two integers N and P. (1 ≤ N, P ≤ 10^9) P is always prime.
Output
Print the N-th smallest positive integer whose smallest prime factor is P. If that number is greater than 10^9, print 0.