COCI 2008/2009, Contest #2
Task RESETO
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.
Input
The integers N and K (2 ≤ K < N ≤ 1000).Output
Output the K-th number to be crossed out.Examples
Input7 3 Output6 |
Input15 12 Output7 |
Input10 7 Output9 |
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.
All Submissions
Best Solutions
Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Nov 21, 2008
Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
Comments (Search)
3. Cross out P and all its multiples that aren't already crossed out.
tip: ppl get annoyed if u type liek this.
late reply
LOLZ
It helps us debug if you indent your code.
BTW, you don't always have to copy codes from PEG. Try making codes of your own, following what they taught you with the original code.
~helios