Cod sursa(job #1253480)

Utilizator space.foldingAdrian Soucup space.folding Data 1 noiembrie 2014 13:27:23
Problema Sum Scor 55
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 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

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

	istringstream iss(s);

	int n, x;

	iss >> n;

	sigma(100007);

	for(int i = 0; i < n; i++)
	{
		iss >> x;
		cout << 2LL * phi[x] * x << endl;
	}

	return 0;
}