fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
Codeforces Round 1047-B (Div. 3) Fun Permutation
최초 업로드: 2025-09-07 18:13:00
최근 수정 시간: 2025-09-07 19:17:46
게시자: rlatjwls3333
카테고리: Codeforces
조회수: 5
# B. Fun Permutation [문제 링크](https://codeforces.com/contest/2137/problem/B) ## Problem Statement You are given a permutation $p$ of size $n$. Your task is to find a permutation $q$ of size $n$ such that $\gcd(p_i+q_i, p_{i+1}+q_{i+1}) \ge 3$ for all $1 \le i < n .$ In other words, the greatest common divisor of the sums at any two adjacent positions should be at least $3$. It can be shown that this is always possible. ## Input Each test contains multiple test cases. The first line contains the number of test cases $t$ $(1 \le t \le 10^{4})$. The description of the test cases follows. The first line contains an integer $n$ $(2 \le n \le 2\cdot 10^{5})$. The second line contains $n$ integers $p_1, p_2, \ldots, p_n$ $(1 \le p_i \le n)$. It is guaranteed that the given array forms a permutation. It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^{5}$. ## Output For each test case, output the permutation $q$ on a new line. If there are multiple possible answers, you may output any. ## Footnotes A permutation of length $m$ is an array consisting of $m$ distinct integers from $1$ to $m$ in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4] is also not a permutation (m=3 but there is 4 in the array). $\gcd(x,y)$ denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers $x$ and $y$. ## 풀이 모든 수를 $2n$이 되도록 순열 q를 만들었다. ``` c++ #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while(t--) { int n; cin >> n; for(int i=0;i<n;i++) { int p; cin >> p; cout << n-p+1 << ' '; } cout << '\n'; } } ```