Cod sursa(job #416872)

Utilizator skullLepadat Mihai-Alexandru skull Data 13 martie 2010 17:12:45
Problema Fractii Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <stdio.h>
#include <math.h>
#define nmax 1000000

using namespace std;

int n;
unsigned int nrt, phi[nmax];

void citire ()
{
	scanf("%d",&n);
}

void solve ()
{
	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];
}

int main ()
{
	freopen("fractii.in","r",stdin);
	freopen("fractii.out","w",stdout);
	citire ();
	solve ();
	nrt = 1;
	for (int i = 2; i <= n; i++)
		nrt += phi[i] *2;
	printf("%d",nrt);
}