Cod sursa(job #3258514)

Utilizator Ruxandra009Ruxandra Vasilescu Ruxandra009 Data 22 noiembrie 2024 23:00:45
Problema Pairs Scor 100
Compilator cpp-64 Status done
Runda cex_3 Marime 0.65 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream f("pairs.in");
ofstream g("pairs.out");

const long long nmax = 1000005;
long long fr[nmax], maxi, n, ans[nmax];

int main()
{
    f >> n;
    for(long long i = 1; i <= n; i ++)
    {
        long long x; f >> x;
        fr[x] ++; maxi = max(maxi, x);
    }

    for(long long i = maxi; i >= 1; i --)
    {
        for(long long j = i; j <= maxi; j += i)
            ans[i] += fr[j];

        ans[i] = 1LL * (ans[i] + 1) * ans[i] / 2;

        for(long long j = 2 * i; j <= maxi; j += i)
            ans[i] -= ans[j];
    }

    g << ans[1];
    return 0;
}