COCI '08 Contest 2 #2 Reseto

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 32M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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, find the K^{th} integer to be crossed out.

Input Specification

The integers N and K (2 \le K < N \le 1000).

Output Specification

Output the K^{th} number to be crossed out.

Sample Input 1

7 3

Sample Output 1


Sample Input 2

15 12

Sample Output 2


Sample Input 3

10 7

Sample Output 3


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.


There are no comments at the moment.