The sieve of Eratosthenes is a famous algorithm to find all prime numbers up to $N$. The algorithm is:
- Write down all integers between $2$ and $N$, inclusive.
- Find the smallest number not already crossed out and call it $P$; $P$ is prime.
- Cross out $P$ and all its multiples that aren't already crossed out.
- If not all numbers have been crossed out, go to step 2.
Write a program that, given $N$ and $K$, finds the $K$-th integer to be crossed out.
Input
The integers $N$ and $K$ ($2 \le K < N \le 1000$).
Output
Output the $K$-th number to be crossed out.
Example 1
Input
7 3
Output
6
Example 2
Input
15 12
Output
7
Example 3
Input
10 7
Output
9
We cross out, in order, the numbers 2, 4, 6, 8, 10, 3, 9, 5 and 7. The seventh number is 9.
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.