Cod sursa(job #3246489)
| Utilizator | Data | 3 octombrie 2024 13:44:03 | |
|---|---|---|---|
| Problema | Pairs | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.45 kb |
#include <fstream>
using namespace std;
ifstream in("pairs.in");
ofstream out("pairs.out");
long long n, x, f[1000010], ans[1000010], i, j, mx;
int main()
{
in >> n;
for (i = 1; i <= n; i++)
{
in >> x;
f[x]++;
mx = max(mx, x);
}
for (i = mx; i >= 1; i--)
{
for (j = i; j <= mx; j += i)
ans[i] += f[j];
ans[i] = (ans[i] * (ans[i] - 1)) >> 1;
for (j = i * 2; j <= mx; j += i)
ans[i] -= ans[j];
}
out << ans[1];
}