欧拉函数及相关定理
欧拉函数
定义
\(\varphi(n)\) 表示小于等于\(n\)的与\(n\)互质的数的个数。
性质
- \(\varphi\)为积性函数,即\(\varphi(a\cdot b)=\varphi(a)\cdot\varphi(b)\) \((a\perp b)\)
- 根据定义可知,$\varphi(p)=p-1 $ \((p\in prime)\)
- 根据定义可知,\(\varphi(p^k)=p^k-p^{k-1}\)
- 由第一分解定理,设\(n=\prod_{i=1}^r p_i^{k_i}\) ,\(\varphi(n)=n\cdot\prod_{i=1}^r\frac{p_i-1}{p_i}=n\cdot\prod_{i=1}^r(1-\frac{1}{p_i})\)
- \(n=\sum_{d|n}\varphi(d)\)
欧拉定理
若\(\gcd(a,b)=1\),则\(a^{\varphi(b)}\equiv 1\pmod b\)
当\(b\in prime\), \(a^{b-1}\equiv 1\pmod b\)就是费马小定理
扩展欧拉定理
\[a^b\equiv\begin{cases}
a^{b\mod\varphi(p)} &\gcd(a,p)=1\\
a^b &\gcd(a,p)\ne1,b\le\varphi(p)\\
a^{b\mod\varphi(p)+\varphi(p)} &\gcd(a,p)\ne1,b>\varphi(p)
\end{cases}\pmod p
\]
一些模板
线性筛欧拉函数
int ss[N],cnt,vs[N],fi[N];
il void init(int n){
fi[1]=1;
for(ri int i=2;i<=n;++i){
if(!vs[i]) ss[++cnt]=i,fi[i]=i-1;
for(ri int j=1;j<=cnt&&ss[j]*i<=n;++j){
vs[i*ss[j]]=1;
if(i%ss[j]) fi[i*ss[j]]=fi[i]*fi[ss[j]];
else{fi[i*ss[j]]=fi[i]*ss[j];break;}
}
}
return;
}
求一个数的欧拉函数
il int fi(int n){
int as=n,res=n;
for(ri int i=2;i*i<=res;++i){
if(res%i==0){
while(res%i==0) res/=i;
as=as/res*(res-1);
}
}
if(res>1) as=as/res*(res-1);
return as;
}
资料
练习题
I went to the woods because I wanted to live deliberately, I wanted to live deep and suck out all the marrow of life, and not when I had come to die, discover that I had not live.