Skip to content

Instantly share code, notes, and snippets.

@ssavi
ssavi / euler_phi.cpp
Created January 22, 2017 05:32 — forked from cslarsen/euler_phi.cpp
Euler's totient function phi --- a fast implementation in C++
/*
* Euler's totient function phi(n).
* http://en.wikipedia.org/wiki/Euler%27s_totient_function
*
* This is an *EXTREMELY* fast function and uses
* several tricks to recurse.
*
* It assumes you have a list of primes and a fast
* isprime() function. Typically, you use a bitset
* to implement the sieve of Eratosthenes and use