**Hello everyone,**↵
↵
I’m currently stuck on a Codeforces problem — [Problem 2137B](https://mirror.codeforces.com/problemset/problem/2137/B). While reading the [official editorial](https://mirror.codeforces.com/blog/entry/146121), I got confused about one particular transformation step:↵
↵
> Each element is replaced by `n + 1 - p[i]`.↵
↵
I understand the use of `n + 1`, since we’re working with adjacent elements and need a length of `n + 1`.↵
However, I don’t quite understand **why we subtract `p[i]`**.↵
↵
Also, I noticed that the editorial mentions a condition like:↵
<math xmlns="http://www.w3.org/1998/Math/MathML">↵
<mi>G</mi>↵
<mi>C</mi>↵
<mi>D</mi>↵
<mo stretchy="false">(</mo>↵
<msub>↵
<mi>p</mi>↵
<mi>i</mi>↵
</msub>↵
<mo>+</mo>↵
<msub>↵
<mi>q</mi>↵
<mi>i</mi>↵
</msub>↵
<mo>,</mo>↵
<msub>↵
<mi>p</mi>↵
<mrow class="MJX-TeXAtom-ORD">↵
<mi>i</mi>↵
<mo>+</mo>↵
<mn>1</mn>↵
</mrow>↵
</msub>↵
<mo>+</mo>↵
<msub>↵
<mi>q</mi>↵
<mrow class="MJX-TeXAtom-ORD">↵
<mi>i</mi>↵
<mo>+</mo>↵
<mn>1</mn>↵
</mrow>↵
</msub>↵
<mo stretchy="false">)</mo>↵
<mo>≥<!-- ≥ --></mo>↵
<mn>3</mn>↵
</math>↵
↵
I’m wondering if this relates to the property↵
`gcd(a, b) = gcd(a - b, b)`↵
**where (a > b)**.↵
Is that property being applied here?↵
↵
And finally, does the condition hold simply because (n > 3) (since (n + 1 > 3)) — or is there a deeper reason behind it?↵
↵
~~~~~↵
// C++ Version of thecodelogic↵
#include <bits/stdc++.h>↵
using namespace std;↵
↵
#define endl '\n'↵
↵
int main() {↵
ios::sync_with_stdio(false);↵
cin.tie(nullptr);↵
↵
int t; cin >> t;↵
while (t--) {↵
int n; cin >> n;↵
vector<int> a(n), b(n);↵
for (int i = 0; i < n; i++) cin >> a[i];↵
for (int i = 0; i < n; i++) b[i] = n - a[i] + 1; // ??↵
for (int i = 0; i < n; i++) cout << b[i] << " ";↵
cout << endl;↵
}↵
↵
return 0;↵
}↵
~~~~~↵
↵
I’d really appreciate it if someone could explain this step more clearly. I’m still a beginner, so a simple explanation would be very helpful.↵
↵
Thank you in advance! ↵
↵
↵
↵
↵
↵
I’m currently stuck on a Codeforces problem — [Problem 2137B](https://mirror.codeforces.com/problemset/problem/2137/B). While reading the [official editorial](https://mirror.codeforces.com/blog/entry/146121), I got confused about one particular transformation step:↵
↵
> Each element is replaced by `n + 1 - p[i]`.↵
↵
I understand the use of `n + 1`, since we’re working with adjacent elements and need a length of `n + 1`.↵
However, I don’t quite understand **why we subtract `p[i]`**.↵
↵
Also, I noticed that the editorial mentions a condition like:↵
<math xmlns="http://www.w3.org/1998/Math/MathML">↵
<mi>G</mi>↵
<mi>C</mi>↵
<mi>D</mi>↵
<mo stretchy="false">(</mo>↵
<msub>↵
<mi>p</mi>↵
<mi>i</mi>↵
</msub>↵
<mo>+</mo>↵
<msub>↵
<mi>q</mi>↵
<mi>i</mi>↵
</msub>↵
<mo>,</mo>↵
<msub>↵
<mi>p</mi>↵
<mrow class="MJX-TeXAtom-ORD">↵
<mi>i</mi>↵
<mo>+</mo>↵
<mn>1</mn>↵
</mrow>↵
</msub>↵
<mo>+</mo>↵
<msub>↵
<mi>q</mi>↵
<mrow class="MJX-TeXAtom-ORD">↵
<mi>i</mi>↵
<mo>+</mo>↵
<mn>1</mn>↵
</mrow>↵
</msub>↵
<mo stretchy="false">)</mo>↵
<mo>≥<!-- ≥ --></mo>↵
<mn>3</mn>↵
</math>↵
↵
I’m wondering if this relates to the property↵
`gcd(a, b) = gcd(a - b, b)`↵
**where (a > b)**.↵
Is that property being applied here?↵
↵
And finally, does the condition hold simply because (n > 3) (since (n + 1 > 3)) — or is there a deeper reason behind it?↵
↵
~~~~~↵
// C++ Version of the
#include <bits/stdc++.h>↵
using namespace std;↵
↵
#define endl '\n'↵
↵
int main() {↵
ios::sync_with_stdio(false);↵
cin.tie(nullptr);↵
↵
int t; cin >> t;↵
while (t--) {↵
int n; cin >> n;↵
vector<int> a(n), b(n);↵
for (int i = 0; i < n; i++) cin >> a[i];↵
for (int i = 0; i < n; i++) b[i] = n - a[i] + 1; // ??↵
for (int i = 0; i < n; i++) cout << b[i] << " ";↵
cout << endl;↵
}↵
↵
return 0;↵
}↵
~~~~~↵
↵
I’d really appreciate it if someone could explain this step more clearly. I’m still a beginner, so a simple explanation would be very helpful.↵
↵
Thank you in advance! ↵
↵
↵
↵
↵



