CCC '14 S1 - Party Invitation

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

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
Canadian Computing Competition: 2014 Stage 1, Junior #4, Senior #1

You are hosting a party and do not have room to invite all of your friends. You use the following unemotional mathematical method to determine which friends to invite.

Number your friends 1, 2, \dots, K and place them in a list in this order. Then perform m rounds. In each round, use a number to determine which friends to remove from the ordered list.

The rounds will use numbers r_1, r_2, \dots, r_m . In round i remove all the remaining people in positions that are multiples of r_i (that is, r_i, 2r_i, 3r_i, \dots) The beginning of the list is position 1.

Output the numbers of the friends that remain after this removal process.

Input Specification

The first line of input contains the integer K (1 \le K \le 100). The second line of input contains the integer m (1 \le m \le 10), which is the number of rounds of removal. The next m lines each contain one integer. The i^{th} of these lines (1 \le i \le m) contains r_i (2 \le r_i \le 100) indicating that every person at a position which is multiple of r_i should be removed.

Output Specification

The output is the integers assigned to friends who were not removed. One integer is printed per line in increasing sorted order.

Sample Input


Output for Sample Input


Explanation of Output for Sample Input

Initially, our list of invitees is {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. There will be two rounds of removals. After the first round of removals, we remove the even positions (i.e., every second position), which causes our list of invitees to be {1, 3, 5, 7, 9}. After the second round of removals, we remove every 3rd remaining invitee: thus, we keep 1 and 3, remove 5 and keep 7 and 9, which leaves us with an invitee list of {1, 3, 7, 9}.


  • -1
    MartyBoiiiii  commented on April 19, 2020, 5:29 p.m.

    but the example enters 2 and 3, but the example output includes 3 but not 2. How does that make sense? 3 is a multiple of 3 and 2 is a multiple of 2.

    • 2
      AlanL  commented on April 20, 2020, 10:07 p.m.

      The problem isn't removing by multiples, it's removing by indexes. If you read the explanation output, it explains how the sample works.