Cod sursa(job #923805)

Utilizator SagunistuStrimbu Alexandru Sagunistu Data 23 martie 2013 21:01:26
Problema Fractii Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include <iostream>
#include <fstream>

using namespace std;
int phi[1000010];
int main()
{ifstream fin("fractii.in");
ofstream fout("fractii.out");
int i,j,n,nr;
fin>>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]/=i;
             phi[j]=phi[j]*(i-1);
            }
for(i=2,nr=0;i<=n;i++)
    nr+=phi[i];
fout<<2*nr+1;
    return 0;
}