Cod sursa(job #3312332)

Utilizator Ruxandra009Ruxandra Vasilescu Ruxandra009 Data 27 septembrie 2025 16:27:33
Problema Pairs Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <algorithm>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

const int nmax = 1e5 + 5;

int n, v[nmax], fr[nmax * 10];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n; int nr = 0;
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
		nr = max(nr, v[i]);

		for(int d = 1; d * d <= v[i]; d ++)
			if (v[i] % d == 0)
				fr[d]++, fr[v[i] / d]++;
	}

	for (int i = nr; i >= 1; i--)
	{
		fr[i] = (fr[i] - 1) * fr[i] / 2;
		for (int j = 2 * i; j <= nr; j += i)
			fr[i] -= fr[j];
	}

	cout << fr[1];
	return 0;
}