Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- int32_t main()
- {
- cin.tie(nullptr)->sync_with_stdio(false);
- int n;
- cin >> n;
- vector<int> a(n + 1);
- for (int i = 1; i <= n; ++i)
- {
- cin >> a[i];
- }
- set<pair<int, int>> ans;
- for (int i = 1; i <= n; ++i)
- {
- for (int k = 2; k * i <= a[i]; ++k)
- {
- int left = a[i] - k * i;
- if (left % (k - 1) == 0)
- {
- int j = left / (k - 1);
- if (j >= 1 && j <= n && i != j)
- {
- if (__gcd(a[i] + j, a[j] + i) == i + j)
- {
- ans.insert({min(i, j), max(i, j)});
- }
- }
- }
- }
- }
- int fixedpoints = 0;
- for (int i = 1; i <= n; ++i)
- {
- if (a[i] == i)
- {
- fixedpoints++;
- }
- }
- cout << (int)ans.size() + fixedpoints * (fixedpoints - 1) / 2;
- }
Add Comment
Please, Sign In to add comment