Cod sursa(job #92337)

Utilizator recviemAlexandru Pana recviem Data 14 octombrie 2007 22:47:19
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <stdio.h>
using namespace std;

	long long totient[1000000];
    int n;
	long long sum;

void citire()
{
    freopen("fractii.in","r",stdin);
    scanf("%d",&n);
}

void ciur()
{
    for (int i=4;i<n+1;i+=2)
        totient[i]=totient[i]-totient[i]/2;
    totient[2]=1;
	for (int i=3;i<n+1;i+=2)
	{
		if (totient[i]==i)
		{
		for(int j=2*i;j<n+1;j+=i)
			totient[j]=totient[j]-totient[j]/i;
        totient[i]=i-1;
		}
	}
}

void scrie()
{
    freopen("fractii.out","w",stdout);
    printf("%lld",sum);
    fclose(stdout);
}

int main()
{
    citire();
    for (int i=0;i<n+1;i++)
        totient[i]=i;
    for (int i=0;i<n+1;i++)
        totient[i]=i;
    sum = 1;
	ciur();
    for (int i=2;i<=n;i++)
        sum += 2*totient[i];
    scrie();
    return 0;
}