Cod sursa(job #1148962)

Utilizator ELHoriaHoria Cretescu ELHoria Data 21 martie 2014 12:55:39
Problema Sum Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <iomanip>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	ifstream cin("sum.in");
	ofstream cout("sum.out");

	const int Xmax = int(1e5) + 5;
	vector<int> ans(Xmax, -1);
	for (int i = 1; i < Xmax; i++) {
		ans[i] = i;
	}

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


	int testCount;
	cin >> testCount;
	while (testCount--) {
		int x;
		cin >> x;
		cout << 2LL * ans[x] * x  << "\n";
	}
	return 0;
}