Euler totient function (phi) - YessineJallouli/Competitive-Programming GitHub Wiki

Generate Euler function :

#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int N = 1e5+7;
int phi[N];

int main() {
    for (int i = 0; i < N; i++)
        phi[i] = i;
    for (int i = 1; i < N; i++) {
        for (int j = 2 * i; j < N; j += i) {
            phi[j] -= phi[i];
        }
    }
}