Problem list
Log in
#coci00080 · COCI 2008/2009 Contest 2

Reseto

Silver IV 1.0 s 32 MB

The sieve of Eratosthenes is a famous algorithm to find all prime numbers up to $N$. The algorithm is:

  1. Write down all integers between $2$ and $N$, inclusive.
  2. Find the smallest number not already crossed out and call it $P$; $P$ is prime.
  3. Cross out $P$ and all its multiples that aren't already crossed out.
  4. 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.

Source
COCI 2008/2009 Contest 2
Appears in
Not part of a ladder, contest or set yet.
Accepted 1 Submissions 1 Acceptance 100% Solvers 1

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