Cod sursa(job #529986)

Utilizator Catah15Catalin Haidau Catah15 Data 6 februarie 2011 17:12:34
Problema Sum Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.48 kb
#include <fstream>
#define XMAX 100002
using namespace std;

long long sum[XMAX + 2];

int main()
{
	int n, x;
	
	ifstream f("sum.in");
	ofstream g("sum.out");
	
	f >> n;
	
	for(int i = 1; i <= XMAX; ++i)
		sum[i] = i - 1;
	
	for(int i = 2; i <= XMAX / 2; ++i)
		for(int j = 2 * i; j <= XMAX; j += i)
			sum[j] -= sum[i];
	
	for(int i = 1; i <= n; ++i)
	{
		f >> x;
		
		g << (sum[x] * (long long) x) * 2 << '\n';
	}
	
	f.close();
	g.close();
	
	return 0;
}