TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation of Euler's Totient @description Euler Totient Function is also known as phi function. More...
#include <cassert>
#include <cstdint>
#include <iostream>
Go to the source code of this file.
Namespaces | |
namespace | math |
for assert | |
Functions | |
uint64_t | math::phiFunction (uint64_t n) |
Function to calculate Euler's Totient. | |
static void | test () |
Self-test implementations. | |
int | main (int argc, char *argv[]) |
Main function. | |
Implementation of Euler's Totient @description Euler Totient Function is also known as phi function.
\[\phi(n) = \phi\left({p_1}^{a_1}\right)\cdot\phi\left({p_2}^{a_2}\right)\ldots\]
where \(p_1\), \(p_2\), \(\ldots\) are prime factors of n.
3 Euler's properties:
Applying this 3 properties on the first equation.
\[\phi(n) = n\cdot\left(1-\frac{1}{p_1}\right)\cdot\left(1-\frac{1}{p_2}\right)\cdots\]
where \(p_1\), \(p_2\)... are prime factors. Hence Implementation in \(O\left(\sqrt{n}\right)\).
Some known values are:
Definition in file eulers_totient_function.cpp.
int main | ( | int | argc, |
char * | argv[] ) |
Main function.
argc | commandline argument count (ignored) |
argv | commandline array of arguments (ignored) |
Definition at line 79 of file eulers_totient_function.cpp.
|
static |
Self-test implementations.
Definition at line 61 of file eulers_totient_function.cpp.