Pagini recente » Cod sursa (job #720571) | Cod sursa (job #2203451) | Cod sursa (job #2293363) | Cod sursa (job #1513225) | Cod sursa (job #1567576)
#include <cstdio>
using namespace std;
const int maxx = 1000000;
int nr[1000005],n,aux;
long long total;
bool a[1000005 ];
int main() {
freopen("pairs.in", "r", stdin);
freopen("pairs.out", "w", stdout);
for(int i = 2; i <= maxx; ++i)
if(not nr[i])
for(int j = i; j <= maxx; j += i)
++ nr[j];
for(int i = 2; i * i <= maxx; ++ i)
for(int j = i * i; j <= maxx; j += i*i)
nr[j] = 0;
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%d", &aux);
a[aux] = true;
}
total = (1LL*n*n-n)/2;
for(int i = 2; i <= maxx; ++i)
if(nr[i]) {
aux = 0;
for(int j = i; j <= maxx; j += i)
if(a[j])
++ aux;
if(nr[i] % 2)
total -= (1LL*aux*aux-aux)/2;
else
total += (1LL*aux*aux-aux)/2;
}
printf("%lld\n", total);
return 0;
}