COCI 2008/2009, Contest #2
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.
InputThe integers N and K (2 ≤ K < N ≤ 1000).
OutputOutput the K-th number to be crossed out.
In the third example, we cross out, in order, the numbers 2, 4, 6, 8, 10, 3, 9, 5 and 7. The seventh number is 9.
Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Nov 21, 2008
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3