Cod sursa(job #3322611)

Utilizator raulthestormIlie Raul Ionut raulthestorm Data 14 noiembrie 2025 23:18:51
Problema Sum Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <fstream>
#include <numeric>

using namespace std;
const int NMAX = 1e5;

long long phi[2 * NMAX + 1];

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

void genPhi(int n)
{
	int i, j;
	iota(phi, phi + n + 1, 0);
	//
	for(i = 2; i <= n; ++i)
		if(phi[i] == i)
			for(j = i; j <= n; j += i)
				phi[j] = phi[j] / i * (i - 1);
}

int main()
{
	genPhi(NMAX);
	//
	int n, x;
	f >> n;
	while(n--)
	{
		f >> x;
		g << 2 * x * phi[x] << '\n';
	}
	f.close();
	g.close();
	return 0;
}