Pagini recente » Cod sursa (job #651633) | Cod sursa (job #991689) | Istoria paginii utilizator/raluvlad | Cod sursa (job #966968) | Cod sursa (job #1946302)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int maxn = 1e6 + 100;
int is_in_set[maxn] = {};
ll nr_with_gcd[maxn] = {};
ifstream f("pairs.in");
ofstream g("pairs.out");
int main(){
int n;
f >> n;
for(int i = 0, x; i < n; ++i) f >> x, is_in_set[x] = 1;
for(int i = maxn-1; i; --i){
for(int j = i; j < maxn; j += i) nr_with_gcd[i] += is_in_set[j];
nr_with_gcd[i] *= nr_with_gcd[i] - 1;
nr_with_gcd[i] /= 2;
for(int j = 2*i; j < maxn; j += i)
nr_with_gcd[i] -= nr_with_gcd[j]; }
g << nr_with_gcd[1] << endl;
return 0; }