Cod sursa(job #3273168)

Utilizator DobrePetruDobre Petru Daniel DobrePetru Data 1 februarie 2025 11:08:55
Problema Fractii Scor 0
Compilator cpp-64 Status done
Runda cex_8 Marime 0.92 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
#define ll long long
ll n,rez;
inline ll phi(ll n)
{
    ll d=2,r=n;
    while(n>1&&d*d<=n)
    {
        if(n%d==0){
            r=r/d*(d-1);
            while(n%d==0) n/=d;
        }
        d++;
    }
    if(n>1) r=r/n*(n-1);
    return r;
}
int main()
{
    std :: iosbase :: sync_with_stdio (false); 
    std :: cin.tie(0);
    fin>>n;
    rez=1;
    for(int i=2; i<=n; i++)
    {
       rez+=2*phi(i);
    }
  fout<<rez;
    return 0;
}