Cod sursa(job #2759802)

Utilizator rusenmihai101@gmail.comMihai Rusen [email protected] Data 20 iunie 2021 16:29:07
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
using namespace std;
using ll = long long;
int P[1000001];
int n;

const string name("fractii");
ifstream cin(name + ".in");
ofstream cout(name + ".out");

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

int main(){

    ll s = 0;
    cin >> n;
    Euler();
    for(int i = 1; i <= n; ++i)
        s += P[i];
    cout << s * 2 - 1;

    return 0;
}


/*

           n!
     ------------- = n! * k^-1 * (n - k)^-1
     k! * (n - k)!

    n! % P * k^-1 % P * (n - k)^-1 % P
*/