| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1.5 초 | 1024 MB | 0 | 0 | 0 | 0.000% |
Your task is to find the lexicographically lowest $K$-gcd equivalent permutation of a given sequence of $N$ positive integers $a_1 , a_2 , \dots , a_N$. Two sequences (that are permutations of each other) $a_1 , a_2 , \dots , a_N$ and $b_1 , b_2 , \dots , b_N$ are considered $K$-gcd equivalent if for every set of $K$ distinct indices from $1$ to $N$, the greatest common divisor (gcd) of the elements in these positions in both sequences is the same.
However, there’s a twist - you are allowed to multiply at most one element of $a$ by a given integer $X$ before finding this lowest $K$-gcd equivalent sequence. You are allowed to not multiply by $X$ at all and keep the same sequence. Additionally, it is guaranteed that $X$ is divisible by only $1$ and itself. You aim to minimize the resulting sequence lexicographically among all possible choices of preprocessing (or choosing not to) of $a$. Note that if you decide to preprocess the sequence, then your result must be a $K$-gcd equivalent of the preprocessed sequence $a$ (i.e. considering the greatest common divisors after the multiplication).
Write a program lex_gcd that solves this problem.
The first line of the input contains one integer $T$, the number of test cases. Each test case consists of three positive integers $N$, $K$, and $X$, followed by $N$ positive integers $a_1 , a_2 , \dots , a_N$.
For each test case, output $N$ integers representing the lexicographically lowest $K$-gcd equivalent sequence to $a$ after performing the allowed preprocessing.
| Subtasks | Points | Required subtasks | $N$ | $X$ | Other constraints |
|---|---|---|---|---|---|
| 1 | 6 | − | $\sum{N} ≤ 5$ | $X = 1$ | − |
| 2 | 19 | 1 | $\sum{N} ≤ 1000$ | $X = 1$ | − |
| 3 | 13 | 1 − 2 | $\sum{N} ≤ 10^5$ | $X = 1$ | − |
| 4 | 4 | 1 | $\sum{N} ≤ 100$ | − | − |
| 5 | 4 | 1, 2, 4 | $\sum{N} ≤ 1000$ | − | − |
| 6 | 31 | − | $\sum{N} ≤ 10^5$ | − | $a_i \ne a_j$ for $i \ne j$ |
| 7 | 23 | 1 − 6 | $\sum{N} ≤ 10^5$ | − | − |
2 3 2 1 2 6 4 4 2 3 7 3 6 9
2 4 6 3 6 9 21
Two test cases. For the first one, no preprocessing is required. The $K$-gcd property is satisfied since the greatest common divisor of all pairs remains $2$. For the second one, preprocessing by multiplying the first element by $3$ results in the lexicographically lowest sequence $3, 6, 9, 21$.