Cod sursa(job #2003299)

Utilizator DavidLDavid Lauran DavidL Data 22 iulie 2017 16:26:48
Problema Fractii Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
#define LL long long
#define MAX 1000000
using namespace std;
ifstream fi("fractii.in");
ofstream fo("fractii.out");

LL phi[MAX+5];
int n;

void getPhi()
{
    phi[2]=1;
    for (int i=3; i<=n; i++)
        phi[i]=i-2+(i&1);
    ///i=2 catre nr. pare >=4 scade 1
    for (int i=3; i<=n; i++)
        for (int j=2*i; j<=n; j+=i)
            phi[j]-=phi[i];
}

int main()
{
    fi.sync_with_stdio(false);
    fo.sync_with_stdio(false);
    fi>>n;
    getPhi();
    LL rez=0;

    for (int numarator=1; numarator<=n; numarator++)
        rez+=phi[numarator];
    rez=rez*2+1;
    fo<<rez;
    fi.close();
    fo.close();
    return 0;
}