Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
- int testcase;
- cin >> testcase;
- while(testcase--) {
- int n;
- cin >> n;
- set <int> s;
- for (int i = 1; i <= n; i++) {
- int x;
- cin >> x;
- if (abs(x - i) != 0) s.insert(abs(x - i));
- }
- int ans = 0;
- for (auto i : s) {
- ans = __gcd(ans, i);
- }
- cout << ans << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement