#P8084. [COCI 2011/2012 #4] BROJ

[COCI 2011/2012 #4] BROJ

Problem Description

Find the NN-th smallest positive integer not exceeding 10910^9 whose smallest prime factor is PP.

Input Format

The first line contains two integers N,PN, P. It is guaranteed that PP is a prime number.

Output Format

Output the required NN-th smallest positive integer not exceeding 10910^9. If the answer exceeds 10910^9, output 00.

1 2
2
2 3
9
1000 1000003
0

Hint

【Constraints and Notes】

  • For 30%30\% of the testdata, the output is less than 10510^5 (including 00).
  • For another 30%30\% of the testdata, P>1000P \gt 1000.
  • For 100%100\% of the testdata, 1N,P1091 \le N, P \le 10^9.

【Hints and Explanation】

This problem is translated from COCI 2011-2012 CONTEST #4 Task 5 BROJ.

The score of this problem follows the original COCI setting, with a full score of 140140.

Translated by ChatGPT 5