Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <cassert>
- #include <map>
- #include <iomanip>
- #include <cstdio>
- #include <cstdlib>
- #include <unordered_map>
- #include <set>
- #include <functional>
- using namespace std;
- using ll = long long;
- #define SZ(a) a.size()
- #define pb(a) push_back(a)
- #define ALL(a) a.begin(), a.end()
- #define mp(a,b) make_pair(a,b)
- int gcd(int a, int b)
- {
- if (b == 0)
- {
- return a;
- }
- return gcd(b, a% b);
- }
- int main() {
- ifstream cin("input.txt");
- int n;
- cin >> n;
- vector <vector<int>> c(n+1,vector<int> (0,0));
- for (int i = 1; i <= n; i++)
- {
- for (int j = 1; j <= n; j++)
- {
- if (gcd(i, j) == 1)
- {
- c[i].pb(j);
- }
- }
- }
- ll ans = 0;
- for (int i = 1; i <= n; i++)
- {
- sort(c[i].begin(), c[i].end());
- }
- for (int a = 1;a <= n; a++)
- {
- int pos = lower_bound(c[a].begin(), c[a].end(), a) - c[a].begin();
- for (int j = pos; j < c[a].size(); j++)
- {
- int cnt = 0;
- int b = c[a][j];
- int it1=0, it2 = 0;
- it1 = pos;
- while (it1 < c[a].size() && it2 < c[b].size() && c[b][it2] <= b)
- {
- if (c[a][it1] == c[b][it2])
- {
- if (a + c[a][it1] > b)
- {
- //cout << a << " " << c[b][it2] << " " << b << '\n';
- cnt++;
- }
- it1++;
- it2++;
- continue;
- }
- if (c[a][it1] < c[b][it2])
- {
- it1++;
- }
- else
- {
- it2++;
- }
- }
- ans += cnt;
- }
- }
- cout << ans;
- //system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement