Cod sursa(job #3204656)

Utilizator andrei.nNemtisor Andrei andrei.n Data 17 februarie 2024 11:20:22
Problema Fractii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <bits/stdc++.h>

using namespace std;

int phi[1000002];

void setPhi(int n)
{
    for(int i=1 ; i<=n; i++)
        phi[i] = i;
    for(int i=2;  i<=n; i++)
        if(phi[i] == i)
        {
            phi[i]--;
            for(int j=2; j * i<=n; j++)
                phi[j * i] = phi[j * i] / i * (i - 1);
        }
}

int main()
{
    ifstream fin ("fractii.in");
    ofstream fout ("fractii.out");
    #define fin cin
    #define fout cout
    int n;
    long long s=0;
    fin>>n;
    setPhi(n);
    for(int i=1; i<=n; i++)
    {
        s += phi[i];
    }
    fout<<s*2-1;
    return 0;
}