Cod sursa(job #3312335)

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

#define ll long long

using namespace std;

const int nmax = 1e5 + 5;
const string txt = "pairs";

ifstream f(txt + ".in");
ofstream g(txt + ".out");

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

int main()
{
	f.tie(NULL);
	f >> n; ll nr = 0;
	for (int i = 1; i <= n; i++) {
		f >> 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];
	}

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