Cod sursa(job #1946301)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 30 martie 2017 05:37:04
Problema Pairs Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

constexpr int maxn = 1e5 + 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; }