Cod sursa(job #154230)

Utilizator algoritmarOvidiu Andrei algoritmar Data 11 martie 2008 00:08:51
Problema Fractii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <fstream>

using namespace std;

#define N_MAX 100001
#define FIN "fractii.in"
#define FOUT "fractii.out"
int phi[N_MAX],n;

int main()
{
	int s = 1;
	fstream fin(FIN);
	ofstream fout(FOUT);

	fin >> n;
	
	//calculate phi function
	for(int i = 1; i <= n; ++i)
		phi[i] = i-1;
	
	for(int i = 2; i <= n; ++i)
		for(int j = 2 * i; j <= n; j+= i)
			phi[j] -= phi[i];
	
	for(int k = 2; k <= n; ++k)
		s += 2*phi[k];

	fout << s << endl ;
	
	return 0;
}













//GetSystemTime(&finishTime);
//cout << startTime.wMilliseconds << endl << finishTime.wMilliseconds << endl << finishTime.wMilliseconds - startTime.wMilliseconds << endl;

//clock_t t2 = clock();
//double a = 4.765;
//cout << t1 <<endl << double(t2-t1)/CLOCKS_PER_SEC << endl << t2 << endl;
//cout << a << endl;