Nu aveti permisiuni pentru a descarca fisierul grader_test26.in
Cod sursa(job #2677081)
| Utilizator | Data | 25 noiembrie 2020 19:30:01 | |
|---|---|---|---|
| Problema | Pairs | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.93 kb |
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
// #define fisier 1
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double dancila = 3.14159265359; // PI
const double eps = 1e-9;
int n, fr[1000002], val;
int cnt[1000002], ans;
void ciur()
{
for(int i = 1000000; i >= 2; --i)
{
val = 0;
for(int j = i; j <= 1000000; j += i)
val += fr[j];
cnt[i] = val * (val-1) / 2;
for(int j = i+i; j <= 1000000; j += i)
cnt[i] -= cnt[j];
ans -= cnt[i];
}
}
int main()
{
#ifdef fisier
ifstream cin("pairs.in");
ofstream cout("pairs.out");
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; ++i)
{
cin >> val;
fr[val]++;
}
ans = n * (n-1) / 2;
ciur();
cout << ans;
return 0;
}
