Cod sursa(job #1148979)

Utilizator ELHoriaHoria Cretescu ELHoria Data 21 martie 2014 13:12:06
Problema Sum Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <cstdio>

const int Xmax = int(1e5) + 5;
int ans[Xmax];

inline int readInt() {
	int result = 0;
	static char ch;
	ch = getc(stdin);
	while (ch < '0' || ch > '9')ch = getc(stdin);

	while ('0' <= ch && ch <= '9') {
		result = result * 10 + (ch - '0');
		ch = getc(stdin);
	}

	return result;
}

int main()
{		
	freopen("sum.in", "r", stdin);
	freopen("sum.out", "w", stdout);
	for (int i = 2; i < Xmax; i++) {
		ans[i] += (i - 1);
		for (int j = i + i; j < Xmax; j += i) {
			ans[j] -= ans[i];
		}
	}

	int x;
	int testCount = readInt();
	while (testCount--) {
		x = readInt();
		printf("%lld\n",2LL * ans[x] * x );
	}
	return 0;
}