Pagini recente » Borderou de evaluare (job #3336622) | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #1663422) | Cod sursa (job #3306552)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("pairs.in");
ofstream fout("pairs.out");
const int NMAX = 100001;
const int VMAX = 1e6 + 1;
int n;
vector<int> cnt(VMAX, 0);
vector<int> freq(VMAX, 0);
signed main()
{
fin >> n;
int vmax = -1;
for(int i = 1; i <= n; i++)
{
int x;
fin >> x;
vmax = max(vmax, x);
freq[x] = 1;
}
for(int i = 1; i <= vmax; i++)
{
for(int j = i; j <= vmax; j += i)
{
cnt[i] += freq[j];
}
// cout << i << ": " << cnt[i] << "\n";
}
vector<int> dp(vmax + 1, 0);
for(int d = vmax; d >= 1; d--)
{
int total = cnt[d] * (cnt[d] - 1) / 2;
for(int i = 2 * d; i <= vmax; i += d)
{
total -= dp[i];
}
dp[d] = total;
}
fout << dp[1];
return 0;
}