Cod sursa(job #3249124)

Utilizator DomnulMilandruMilandru Nicon-David DomnulMilandru Data 14 octombrie 2024 20:37:30
Problema Pairs Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb

#include <fstream>
#include <string.h>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <deque>
using namespace std;
ifstream cin("pairs.in");
ofstream cout("pairs.out");
long long n, x;
long long dp[1000001],M[1000001];
long long maxi;
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        M[x]++;
        maxi = max(maxi, x);
    }
    for (int i = maxi; i >= 1; i--)
    {
        long long s = 0;
        dp[i] = M[i];
        for (int j = i + i; j <= maxi; j = j + i)
        {
            dp[i] = dp[i] + M[j];
            s = s + dp[j];
        }
        dp[i] = (dp[i] * (dp[i] - 1)*1LL) / 2 - s;
    }
    cout << dp[1];
    return 0;
}