Cod sursa(job #2033915)

Utilizator CGrigoreCristi Grigore CGrigore Data 7 octombrie 2017 11:51:37
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.41 kb
#include <fstream>

using namespace std;
ifstream in ("fractii.in");
ofstream out ("fractii.out");
long long n,i,j,s;
int PI[1000001];
int main()
{
    in>>n;
    for(i=1;i<=n;i++)
        PI[i]=i-1;
    PI[1]=1;
    for(i=2;i<=n;i++)
        for(j=2*i;j<=n;j+=i)
            PI[j]-=PI[i];
    for(i=1;i<=n;i++)
        s+=PI[i];
    out<<s*2-1;
    in.close();
    out.close();
    return 0;
}