Cod sursa(job #1253485)

Utilizator space.foldingAdrian Soucup space.folding Data 1 noiembrie 2014 13:29:09
Problema Sum Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <iostream>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <string>
using namespace std;

int phi[100007];


void sigma(int n) {

	for(int i = 0; i <= n; i++) {
		phi[i] = i;
	}

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

	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("sum.in", "r", stdin);
	freopen("sum.out", "w", stdout);
#endif
	cin.sync_with_stdio(false);
	cout.sync_with_stdio(false);

	string s;
	getline(cin, s, '\0');

	istringstream iss(s);
	ostringstream oss;

	int n, x;

	iss >> n;

	sigma(100007);

	for(int i = 0; i < n; i++)
	{
		iss >> x;
		oss << 2LL * phi[x] * x << "\n";
	}
	cout << oss.str();
	return 0;
}