Cod sursa(job #981482)

Utilizator bugyBogdan Vlad bugy Data 7 august 2013 12:00:26
Problema Sum Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <stdio.h>
#include <math.h>
#define dim 100005
using namespace std;

int main()
{
	int n, phi[ dim ], x;
	long long rez;

	for( int i = 2; i < dim; i++ )
		phi[ i ] = i-1;

	for( int i = 2; i < dim; i++ )
		for( int j = 2*i; j < dim; j += i )
			phi[ j ] -= phi[ i ]; 

	FILE *f = fopen("sum.in","r"), *g = fopen("sum.out","w");
	
	fscanf( f,"%d", &n );
	while(n--)
	{	
		fscanf( f,"%d", &x );
		rez =  (long long) (2*phi[x]*x);
		fprintf( g,"%lld\n", rez );
	}
	
fclose( f );	
fclose( g );	
return 0;
}