Problem list
Log in
#coci00211 · COCI 2011/2012 Contest 4

Broj

Diamond V 1.0 s 64 MB

Find the $N$-th smallest positive integer whose least prime factor is P, or state that the result is greater than $10^{9}$.

Input

The first and only line of input contains space seperated integers N and P ($1 \le N$, $P \le 10^{9}$). P will always be prime.

Output

Output a single line with the expected result, or zero if result exceeds $10^{9}$.

Constraints

In test cases worth 30% of total points, expected result will either be less than 100 000, or will exceed $10^{9}$. In test cases worth additional 30% of total points, P will be greater than 1000.

Example 1

Input
1 2
Output
2

Example 2

Input
2 3
Output
9

Example 3

Input
1000 1000003
Output
0
Source
COCI 2011/2012 Contest 4
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code