Python · June 25, 2022 0

CCC ’14 S1/J4 – Party Invitation

https://dmoj.ca/problem/ccc14s1

This is a dmoj 5-point Junior 4 question. It is more complex than it seems. Read on to find the solution and the logic to it!

First, read the question. Without knowing what the question is about, all the rest of this blog will be useless.

First things first, you will need to create a list that has the numbers 1-K. Name it “a”.

One of the most confusing things is, if you remove one of the numbers in the beginning, the positioning of the entire list changes. To solve that, you have to remove from the back.

Create a while loop where if a number is supposed to be removed, it is. Remember to start from the end, and then to the begninning.

Here is an example of a python program using this logic:

a = [i+1 for i in range(int(input()))]
for q in range(int(input())):
    r = int(input())
    x = len(a)
    while x > 0:
        if x % r == 0:
            a.remove(a[x-1])
        x -= 1
for w in a:
    print(w)