Cod sursa(job #2604020)

Utilizator As932Stanciu Andreea As932 Data 21 aprilie 2020 15:00:16
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.43 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");

const int nmax=1000005;

int n;
long long ans,phi[nmax];

int main()
{
    fin>>n;

    for(int i=2;i<=n;i++)
        phi[i]=i-1;

    for(int i=2;i<=n;i++)
    {
        ans+=phi[i];

        for(int j=2;i*j<=n;j++)
            phi[i*j]-=phi[i];
    }

    fout<<1LL*2*ans+1;


    return 0;
}