Learning:欧拉函数

定义:

对正整数n,欧拉函数是小于等于n的数中与n互质的数的数目,又称\phi函数。例如\phi(8)=4

引理:

  1. 如果n为某个素数p,则\phi(p)=p-1
  2. 如果n为某个素数p的幂次\phi(p^a)=p^{a-1}(p-1)
  3. \phi函数为积性函数。
  4. n=\sum_{i=0}^kp_i^{a_i}为正整数n的素数幂乘积表达式,则:\phi(n)=n\prod_{i=1}^k\frac{p_i-1}{p_i}

证明都不难,自己推一推吧。

由引理1,2,3,我们不难可以想到怎么对欧拉函数进行线性筛。代码如下:

int n,m,cnt,ans,x,y,phi[N],prm[N],vis[N];
void init(){
    phi[1]=1;
    for(int i=2;i<N;i++){
        if(!vis[i]){
            prm[cnt++]=i;
            phi[i]=i-1;
        }
        for(int j=0,k=prm[0]*i;j<cnt&&k<N;j++,k=prm[j]*i){
            vis[k]=1;
            if(!(i%prm[j])){
                phi[k]=phi[i]*prm[j];
                break;
            }
            phi[k]=phi[i]*phi[prm[j]];
        }
    }
    return;
}

给几道题:

【POJ3090】Visible Lattice Points

【bzoj4804】欧拉心算

欧拉定理:

am互质,则a^{\phi(m)}\equiv1\pmod m

在证明这个定理之前,我们要先证明另外一个东西:若gcd(c,p)=1,ac\equiv bc\pmod p,则a\equiv b\pmod p

\because gcd(c,p)=1

\thereforec在模p的意义下存在逆元

\because ac\equiv bc\pmod p

\therefore ac\cdot c^{-1}\equiv bc\cdotc^{-1}\pmod p

\therefore a\equiv b\pmod p

接下来我们来证明一下欧拉定理。

证明:

设集合Z=\{x_1,x_2,x_3,...,x_{\phi(m)}\}S=\{ax_1\mod m,ax_2\mod m,ax_3\mod m,...,ax_{\phi(m)}\mod m\}

\because gcd(a,m)=1

\therefore不难得到S=Z

\therefore \prod_{i=1}^{\phi(m)}ax_i\equiv\prod_{i=1}^{\phi(m)}x_i\pmod m

\therefore a^{\phi(m)}\prod_{i=1}^{\phi(m)}x_i=\prod_{i=1}^{\phi(m)}x_i\pmod m

\because gcd(\prod_{i=1}^{\phi(m)}x_i,m)=1

\therefore a^{\phi(m)}\equiv1\pmod m

扩展欧拉定理

a^n\equiv\left\{\begin{matrix} a^{n\mod\phi(m)}&gcd(a,m)=1\\ a^n & gcd(a,m)\not=1,n<\phi(m)\\ a^{(n\mod\phi(m))+\phi(m) &gcd(a,m)\not=1,n\geq\phi(m) \end{matrix}\right.\pmod m

gcd(a,m)=1时,

b=n\mod\phi(m),n=k\phi(m)+b

\because gcd(a,m)=1

由欧拉定理可得:

a^{\phi(m)}\equiv1\pmod m

\therefore a^{k\phi(m)}\equiv1\pmod m

\therefore a^{k\phi(m)}\cdot a^b\equiv a^b\pmod m

\therefore a^{k\phi(m)+b}\equiv a^b\pmod m

\therefore a^n\equiv a^{n\mod \phi(m)}\pmod m

gcd(a,m)\not=1,n<\phi(m)时显然。

gcd(a,m)\not=1,n\geq\phi(m)时,

emmm......

去orz一下yww吧。

来两道题:

【bzoj3884】上帝与集合的正确用法

【bzoj4869】[Shoi2017]相逢是问候

一个重要的性质:

\sum_{d|n}\phi(n)=n

证明:

n=\prod_{i=1}^mp_i^{a_i}为正整数n的素数幂乘积表达式。

不难想到,\sum_{d|n}\phi(n)=\prod_{i=1}^m(1+(p_i-1)\prod_{j=0}^{a_i-1}p_i^j)=\prod_{i=1}^m(1+\frac{(p-1)(1-p^{a_i})}{1-p})=\prod_{i=1}^mp_i^{a_i}=n

这个性质在利用杜教筛求\phi函数的前缀和时非常重要。

差不多就这样啦。

再来道题:

【bzoj3518】点组计数

猜你喜欢

转载自blog.csdn.net/ezoiHQM/article/details/81203126