欧拉函数
欧拉函数
对于任意的正整数\(n\),求在小于等于\(n\)的正整数之中,与\(n\)互质的数的个数,记作\(\varphi(n)\),若有质因子分解为\(n=p_1^{k_1}p_2^{k_2}\cdots p_r^{k_r}\),则其通项公式为:
\[\varphi(n)=n\prod_{i=1}^{r}{\left(1-\frac{1}{p_i}\right)}
\]
证明:
当\(n=p\)是一个质数时,数\(1\)到\(p-1\)都与\(p\)互质,所以\(\varphi(p)=p-1\)
当\(n=p^k\)是一个质数的幂时,有\(\frac{p^k}{p}\)个数不与\(p^k\)互质,所以\(\varphi(p^k)=p^k\left(1-\frac{1}{p}\right)\)
当\(n=p_1^{k_1}p_2^{k_2}\cdots p_r^{k_r}\)时,有
\[\begin{align}
\varphi(p_1^{k_1}p_2^{k_2}\cdots p_r^{k_r}) &= \varphi(p_1^{k_1})\varphi(p_2^{k_2})\cdots\varphi(p_r^{k_r})\\
&= p_1^{k_1}p_2^{k_2}\cdots p_r^{k_r}\left(1-\frac{1}{p_1}\right)\left(1-\frac{1}{p_2}\right)\cdots\left(1-\frac{1}{p_r}\right)\\
&= n\prod_{i=1}^{r}{\left(1-\frac{1}{p_i}\right)}\\
\end{align}\]
这里\(\varphi(p_1^{k_1}p_2^{k_2})=\varphi(p_1^{k_1})\varphi(p_2^{k_2})\),是因为对于数\(a\leq p_1^{k_1}\)与\(p_1^{k_1}\)互质,数\(b\leq p_2^{k_2}\)与\(p_2^{k_2}\)互质,那么由中国剩余定理可以得出模\(p_1^{k_1}p_2^{k_2}\)的唯一解\(c\),且数\(c\)与\(p_1^{k_1}p_2^{k_2}\)互质的充要条件就是数\(a\)与\(p_1^{k_1}\)互质,数\(b\)与\(p_2^{k_2}\)互质
即得证