Cod sursa(job #184205)

Utilizator radu_voroneanuVoroneanu Radu Stefan radu_voroneanu Data 23 aprilie 2008 12:10:25
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <stdio.h>
#define max 1000000

long phi[max+1],i,n;
long long j;

int main()
 {
        freopen("fractii.in","r",stdin);
        freopen("fractii.out","w",stdout);
        scanf("%ld\n",&n);
        for (i=1; i<=n; ++i) phi[i]=i;
        for (i=2; i<=n; ++i)
                if (phi[i]==i)
                        for (j=i; j<=n; j+=i) phi[j]-=phi[j]/i;
        j=1;
        for (i=2; i<=n; ++i) j+=phi[i]<<1;
        printf("%lld\n",j);
        fclose(stdin); fclose(stdout);
        return 0;
 }