P27233 [AtCoder] Swapping Bibs
普及+
题目描述

Problem Description

$ N $ students of JOI High School are standing in a row from west to east. The $ i $-th student from the west end is student $ i $. Each student is wearing a bib with an integer written on it. Initially, student $ i $ has an integer $ A_i $ written on their bib.

There are $ M $ batons, numbered from $ 1 $ to $ M $. For each $k = 1, 2, \ldots, M$, the following operations are performed. The operations for baton $ k $ ($2 \leq k \leq M$) are performed after the operations for baton $ k - 1 $ are completed.

  1. The teacher hands baton $ k $ to student $ 1 $.
  2. The student who receives the baton passes it according to the following rules:
    - Rule: Suppose student $ i $ receives baton $ k $.
    • When $1 \leq i \leq N - 1$: If the remainder of the integer on student $ i $'s bib divided by $ k $ is greater than the remainder of the integer on student $ i + 1 $'s bib divided by $ k $, then student $ i $ and student $ i + 1 $ swap their bibs, and student $ i $ hands the baton to student $ i + 1 $. Otherwise, they do not swap bibs, and student $ i $ hands the baton to student $ i + 1 $.
    • When $ i = N $: Student $ N $ hands the baton back to the teacher.
  3. When the teacher receives baton $ k $ from student $ N $, the operations for baton $ k $ are completed.

Given the initial integers on the students' bibs and the number of batons $ M $, write a program to determine the integers on the students' bibs after the teacher receives baton $ M $ from student $ N $.


Input Format

The input consists of $ 1 + N $ lines.

The first line contains two integers $ N, M $ ($1 \leq N \leq 100$, $1 \leq M \leq 100$), representing the number of students and the number of batons, respectively.

The following $ N $ lines contain one integer each. The $ i $-th line ($1 \leq i \leq N$) contains an integer $ A_i $ ($1 \leq A_i \leq 1000$), representing the initial integer on student $ i $'s bib.

Output Format

The output consists of $ N $ lines. The $ i $-th line ($1 \leq i \leq N$) should contain the integer on student $ i $'s bib after the teacher receives baton $ M $ from student $ N $.


Sample Input and Output

Sample Input #1

6 4
3
2
8
3
1
5

Sample Output #1

2
3
1
8
5
3

Sample Input #2

10 6
1
2
3
4
5
6
7
8
9
10

Sample Output #2

6
1
2
3
10
4
8
7
9
5

Notes/Hints

Sample Explanation 1

In sample input #1, there are 6 students. Initially, the bibs have the integers $ 3, 2, 8, 3, 1, 5 $ in order. There are 4 batons. - After the operations for baton 1, the bibs are $ 3, 2, 8, 3, 1, 5 $. - After the operations for baton 2, the bibs are $ 2, 8, 3, 3, 1, 5 $. - After the operations for baton 3, the bibs are $ 2, 3, 3, 1, 8, 5 $. - After the operations for baton 4, the bibs are $ 2, 3, 1, 8, 5, 3 $.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
6 4 3 2 8 3 1 5
样例输出
2 3 1 8 5 3