Cod sursa(job #2860690)

Utilizator MafteiAlbertAlexandruMaftei Albert-Alexandru MafteiAlbertAlexandru Data 2 martie 2022 22:42:52
Problema Fractii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
#define N 1000002
int phi[N];
void ciur()
{
    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 n;
int main()
{
    ciur();
    fin >> n;
    int s=0;
    s+=n;
    for(int i=2;i<=n;i++)
    {
        s+=phi[i]+1;
    }
    fout << s;
    return 0;
}