数论 欧拉函数

欧拉函数

剩余系

  • 同余类:对于 \(\forall a\in\left[0,m-1\right]\) ,集合 \(\{x|x=a+km,k\in\Z\}\) 的所有数模 \(m\) 同余,余数都是 \(a\) ,该集合称为一个模 \(m\) 的同余类,简记为 \(\overline{a} \mod{m}\)

    • \(m\) 的同余类一共有 \(m\) 个,分别为 \(\overline{0},\overline{1},\dots,\overline{m-1}\) ,他们构成 \(m\) 的完全剩余类
    • 同余类也叫剩余类
  • 完全剩余系:对于 \(m\in\Z^+\) ,有 \(r_1,r_2,\dots,r_m-1,r_m\)\(m\) 个整数,且两两模 \(m\) 不同余,这些同余类所组成的集合叫做模 \(m\) 的完全剩余系

    • 从模 \(m\) 的每个剩余类中任取一个数,所得到的 \(m\) 个数是一个模 \(m\) 的完全剩余系

    • \(\{x_1,x_2,\dots,x_m\}\) 是模 \(m\) 的完全剩余系, \(\gcd(a,m)=1,b\in\Z\) ,有:

      \[\{a\times x_1+b,a\times x_2+b,\dots,a\times x_m+b\} 也是模m的完全剩余系 \]

    • \(m\) 的完全剩余系有且仅有 \(m\) 个整数, \(\{0,1,2,\dots,m-1\}\) 是模 \(m\) 最小的非负完全剩余系

    • \(2|m\) 时: \(\left\{-\frac m2+1,\dots,-1,0,1,\dots,\frac m2\right\}\) 是模 \(m\) 的绝对值最小的完全剩余系

    • \(2\not{|}\ m\) 时: \(\left\{-\frac{m-1}2,\dots,-1,0,1,\dots,\frac{m-1}2\right\}\) 是模 \(m\) 的绝对值最小的完全剩余系

  • 简化剩余系:对于模 \(m\) 的完全剩余系,从中选出与 \(m\) 互质的同余类元素,组成 \(m\) 的简化剩余系

    • \(10\) 的简化剩余系为 \(\left\{\overline{1},\overline{3},\overline{7},\overline{9}\right\}\)
    • \(m\) 的简化剩余系的元素数量记为 \(\varphi(m)\)
  • 性质

    • \(\gcd(a,m)=\gcd(b,m)=1\) ,有 \(a*b\%m\) 属于 \(m\) 的简化剩余系
    • 若集合 \(A=\{x_1,x_2,\dots,x_{\varphi(m)}\}\) 是模 \(m\) 的简化剩余系, \(有a\in\Z,\gcd(a,m)=1\) ,则集合 \(B=\{ax_1,ax_2,\dots,ax_{\varphi(m)}\}\) 也是模 \(m\) 的简化剩余系
    • \(\gcd(m_1,m_2)=1,m_1,m_2\in\N,X=\{x_1,x_2,\dots,x_{\varphi(m_1)},Y=\{y_1,y_2,\dots,y_{\varphi(m_2)}\}\) 。集合 \(X,Y\) 分别是模 \(m_1,m_2\) 的简化剩余系,则 \(A=\{k|k=m_1y+m_2x,x\in X,y\in Y\}\) 是模 \(m_1\times m_2\) 的简化剩余系
    • 在数列 \(\{1,2,\dots,n\}\) 中,与 \(n\) 互质的整数之和是 \(\frac 1 2 n \varphi(n)\)
    • \(\forall n\in\N^+,\sum_{d|n}\varphi(d)=n\)
    • \(p|x\) ,有 \(\varphi(p\times x)=p\times \varphi(x)\)

欧拉函数

  • 定义: \(\varphi(m)\) 表示 \(\{0,1,2,3,\dots,m-1\}\) 中与 \(m\) 互质的数的个数

    • \(\varphi(10)=4\ \ (1,3,7,9)\)
  • 通式:

    \[\varphi(x)=x\times\prod_{i=1}^{n}\left(1-\frac1{p_i}\right) \]

    • 上式中:\(p_i表示x的质因数,x\in\N^+\)
    • 规定:\(\varphi(1)=1\)
    • \(x\) 为质数,则 \(x\)\([1,x-1]\) 中每一个数互质,有 \(\varphi(x)=x-1\)
  • 证明

    \[\begin{align} \notag i)&\ 当\ x\ 为质数时\\\notag &\therefore\ \varphi(x)=x-1=x\times\left(1-\frac1x\right)\\\notag &\therefore\ 通式成立\\\notag ii)&\ 当\ x=p^k,p为质数时\\\notag &\because\ x只有一个质因子p\\\notag &\therefore\ [1,x-1]中除p的倍数以外均与x互质\\\notag &\because\ [1,x-1]中p的倍数包括1\times p,2\times p,\dots,p^{k-1}\times p\\\notag &\ 共\ p^{k-1}个\\\notag &\therefore\ \varphi(x)=p^k-p^{k-1}=p^k\times\left(1-\frac1p\right)=x\times\left(1-\frac1p\right)\\\notag &\therefore\ 通式成立\\\notag iii)\ &当\ x\ 为其他情况时\\\notag &由\ 算术基本定理:\forall x\in[2,+\infty)且x\in\Z\\\notag &若\ x\ 不是质数,则\ x\ 可以唯一分解为有限个质数的乘积\\\notag &\ x=p_1^{k_1}\times p_2^{k_2}\times\dots p_n^{k_n},其中\ p_1,p_2,\dots,p_n\ 为质数\\\notag &\therefore\ 由ii)知\\\notag &\ \ \ \ \varphi(p_1^{k_1})=p_1^{k_1}\times \left(1-\frac1{p_1}\right)\\\notag &\ \ \ \ \varphi(p_2^{k_2})=p_2^{k_2}\times\left(1-\frac1{p_2}\right)\\\notag &\ \ \ \ \vdots\\\notag &\ \ \ \ \varphi(p_n^{k_n})=p_n^{k_n}\times\left(1-\frac1{p_n}\right)\\\notag &\because\ \varphi(x)=\varphi(p_1^{k_1}\times p_2^{k_2}\times\dots\times p_n^{k_n})\\\notag &\ 且\ p_1^{k_1},p_2^{k_2},\dots,p_n^{k_n}\ 互质\\\notag &\therefore\ 根据欧拉函数的数积性,有\\\notag &\varphi(x)=\varphi(p_1^{k_1}\times p_2^{k_2}\times\dots\times p_n^{k_n})\\\notag &\ =\varphi(p_1^{k_1})\times \varphi(p_2^{k_2})\times\dots\times\varphi(p_n^{k_n})\\\notag &\ =p_1^{k_1}\times p_2^{k_2}\times\dots\times p_n^{k_n}\times\left(1-\frac1{p_1}\right)\times\left(1-\frac1{p_2}\right)\times\dots\times\left(1-\frac1{p_n}\right)\\\notag &\ =x\times\left(1-\frac1{p_1}\right)\times\left(1-\frac1{p_2}\right)\times\dots\times\left(1-\frac1{p_n}\right)\\\notag &\ =x\times\prod_{i=1}^n\left(1-\frac1{p_i}\right)\\\notag &\therefore\ 通式成立\\\notag \therefore\ &综上i)ii)iii),可知\\\notag &\varphi(x)=x\times\prod_{i=1}^n\left(1-\frac1{p_i}\right) \end{align} \]

    • 关于上述证明用到的欧拉函数数积性的证明

      证明:若 \(\gcd(m,n)=1\) ,有 \(\varphi(m\times n)=\varphi(m)\times\varphi(n)\)

      \(x\in[1,mn]且x\in\Z\) 构造为下面的矩阵

      \[\begin{matrix} 1&2&3&\dots&r&\dots&m\\ m+1&m+2&m+3&\dots&m+r&\dots&2m\\ 2m+1&2m+2&2m+3&\dots&2m+r&\dots&3m\\ \vdots&\vdots&\vdots&\vdots&\vdots&\ddots&\vdots\\ (n-1)m+1&(n-1)m+2&(n-1)m+3&\dots&(n-1)m+r&\dots&nm \end{matrix} \]

      \(\varphi(mn)\) 是上面的矩阵中与 \(mn\) 互质的数的个数

      \(\because\ 若\gcd(a,m)=1,\gcd(b,m)=1,则\gcd(ab,m)=1\)

      \(\therefore\) 上面的矩阵中与 \(mn\) 互质的数就是同时与 \(n,m\) 互质的数

      \(\because\) \(\gcd(km+r,m)=\gcd(r,m),0\le r\lt m,k\in\Z^+\) ,所以当 \(\gcd(r,m)=1\) 时第 \(r\) 列的数都与 \(m\) 互质,故与 \(m\) 互质的元素共有 \(\varphi(m)\)

      假定 \(\gcd(m,r)=1\) ,有 \(\{r,r+m,r+2m,\dots,r+(n-1)m\}\) 均与 \(m\) 互质

      \(\because \{0,1,2,\dots,n-1\}\) 是模 \(n\) 的完全剩余系且\(\gcd(n,m)=1,r\in\Z^+\)

      \(\therefore\{r,r+m,r+2m,\dots,r+(n-1)m\},r\in\Z^+\) 也是模 \(n\) 的完全剩余系

      $\therefore $ 每一列都恰好有 \(\varphi(n)\) 个数与 \(n\) 互质

      $\therefore $ 由乘法原理,同时与 \(n,m\) 互质的数有 \(\varphi(n)\times\varphi(m)\) 个,即: \(\varphi(mn)=\varphi(m)\times\varphi(n),\gcd(m,n)=1\)

  • 性质及证明

    • \(m\perp n\Rightarrow\varphi(m\times n)=\varphi(m)\times\varphi(n)\) 证明见上

    • \(p\ |\ x\Rightarrow\varphi(p\times x)=p\times\varphi(x)\)

    \[\begin{align} \notag证&明:\\\notag &\because\ p\ |\ x\\\notag &设\ x=p_1\times p_2\times\dots\times p_n\\\notag &\therefore\ p=p_{r_1}\times p_{r_2}\times\dots\times p_{r_k}\\\notag &\therefore\ p\times x与 x有相同的质因子\\\notag &\therefore\ \varphi(p\times x)=p\times x\times\prod_{i=1}^n\left(1-\frac 1 {p_i}\right)\\\notag &\therefore\ \varphi(p\times x)=p\times\varphi(x) \end{align} \]

    • \(2\not{|}\ n\Rightarrow\varphi(2\times n)=\varphi(n)\)

    \[\begin{align} \notag证&明:\\\notag &\because\ 2\not{|}\ n\Rightarrow n的质因子中没有2\\\notag &设\ p_i\ 是n的质因子 \\\notag &\therefore\ \varphi(2\times n)=2\times n\times \left(1-\frac 12\right)\times\prod_{i=1}^n\left(1-\frac 1{p_i}\right)\\\notag &\ \ \ \ =n\times\prod_{i=1}^n\left(1-\frac 1{p_i}\right)=\varphi(n) \end{align} \]

    • \[设A=\left\{x\in\Z|x\in\left[1,n\right]且x\perp n\right\}\\ \sum A=\frac 12n\varphi(n) \]

      \[\begin{align} \notag证&明:\\\notag &\ 设\ \{a_1,a_2,\dots,a_{\varphi(n)}\},(1\le a_i\lt n)是模n的简化剩余系\\\notag &\because\ a_i\perp n\Rightarrow n-a_i\perp n\\\notag &\ \ \ \ \ \ 1\le a_i\lt n\Rightarrow 1\le n-a_i\lt n\\\notag &\therefore\ \{a_1,a_2,\dots,a_{\varphi(n)}\}=\{n-a_1,n-a_2,\dots,n-a_{\varphi(n)}\}\\\notag &\therefore\ a_1+a_2+\dots+a_n=(n-a_1)+(n-a_2)+\dots+(n-a_{\varphi(n)})\\\notag &\Rightarrow a_1+a_2+\dots+a_n=\frac 12n\varphi(n) \end{align} \]

    • \[\forall n\in\N^+,\sum_{d|n}\varphi(d)=n \]

      \[\begin{align} \notag证明&:用数学归纳法证明\\\notag i)&\ 当n=1时,显然等式成立\\\notag ii)&\ 若当n=k时等式成立,则\\\notag &当\ n=k\times p^t,p为质数且p\perp k时\\\notag &\because\ 设k的所有因子为A=\{1,\dots,k\}\\\notag &设\ B=\{x|x=a\times p^b,a\in A,b\in[1,t]\}\\\notag &\because p\perp k\\\notag &\therefore \forall x\in\{x|x=p^i,i\in[1,t]\},y\in A\\\notag &\ \ x\perp y\\\notag &\therefore\ k\times p^t的所有因子为 A\cup B,且A\cap B=\varnothing\\\notag &\therefore\\\notag &\sum_{d|k\times p^t}\varphi(d)=\sum_{d|k}\varphi(d)+\sum_{i=1}^{t}\sum_{d|k}\varphi(d\times p^i)\\\notag &\ \ \ \ \ \ =k+\sum_{i=1}^t\left(\sum_{d|k}(\varphi(p^i)\times\varphi(d))\right)\\\notag &\ \ \ \ \ \ =k+\sum_{i=1}^t\left(\sum_{d|k}\left((p^i-p^{i-1})\times\varphi(d)\right)\right)\text{(欧拉函数通式)}\\\notag &\ \ \ \ \ \ =k+\sum_{i=1}^t\left(p^{i-1}\times(p-1)\times\sum_{d|k}\varphi(d)\right)\\\notag &\ \ \ \ \ \ =k+k\times(p-1)\times\sum_{i=1}^{t}p^{i-1}\\\notag &\ \ \ \ \ \ =k+k\times(p-1)\times\frac{1\times\left(1-p^t\right)}{1-p}\text{(等比数列求和)}\\\notag &\ \ \ \ \ \ =k+k\times(p^t-1)=p^t\times k=n\\\notag &\therefore\ 等式成立\\\notag 综&上i)ii),可知\forall n\in\N^+,\sum_{d|n}\varphi(d)=n \end{align} \]

  • 用法

    • \(O(\sqrt n)\)
    template<class t>t phi(t n){
        t res=n;
        //n在区间[√n,n]之间的质因子最多有一个为n
        for(t i=2;i*i<=n;i++){
            //公式 phi(n)=n*1/i*(i-1)
            if(n%i==0)res=res/i*(i-1);
            while(n%i==0)n/=i;//除掉所有的因子i
        }
        //如果n!=1说明存在大于√n的质因子为n
        if(n>1)res=res/n*(n-1);
        return res;
    }
    
  • 筛法求欧拉函数:给定一个正整数 \(n\)\([1,n]\) 中每个数的欧拉函数

    • 需要的基本性质

      \[\begin{align} \notag1)&\ 若p为质数,有\ \varphi(p)=p-1\\\notag 2)&\ 若p为质数且\ p|x\ ,有\varphi(p\times x)=p\times\varphi(x)\\\notag 3)&\ 若p为质数且\ p\not{|}\ \ x\ ,有\varphi(p\times x)=\varphi(p)\times\varphi(x) \end{align} \]

    • 用法 \(O(n)\)

      typedef long long lld;
      lld phi[maxn],pri[maxn],cnt;
      bool mark[maxn];
      void getphi(int n){
          phi[1]=1;
          for(int i=2;i<=n;i++){
              if(!mark[i]){//i是质数
                  pri[++cnt]=i;
                  phi[i]=i-1;
              }
              for(int j=1;j<=cnt&&i*prime[j]<=n;++j){
                  mark[i*pri[j]]=1;
                  if(i%pri[j]==0){
                      phi[i*pri[j]]=pri[j]*phi[i];
                      break;
                  }
                  phi[i*pri[j]]=(pri[j]-1)*phi[i];
              }
          }
      }
      

欧拉定理

  • 对于任意 \(a,n,\gcd(a,n)=1\) ,有 \(a^{\varphi(n)}\equiv1\pmod n\)

    \[\begin{align} \notag证明&:\\\notag &设\ n\ 的简化剩余系为\ R=\{x_1,x_2,\dots,x_{\varphi(n)}\}\\\notag &令\ S=\{a\times x_1\%n,a\times x_2\%n,\dots,a\times x_{\varphi(n)}\%n\}\\\notag &\because\ a\perp n\\\notag &\therefore\ S=R\\\notag &\therefore\ x_1\times x_2\times\dots\times x_{\varphi(n)}=(a\times x_1\%n)\times(a\times x_2\%n)\times\dots\times(a\times x_{\varphi(n)}\%n)\\\notag &\ \ \ \ \ \ =(a\times x_1)\times(a\times x_2)\times\dots\times(a\times x_{\varphi(n)})\%n\\\notag &\ \ \ \ \ \ =a^{\varphi(n)}\times x_1\times x_2\times\dots\times x_{\varphi(n)}\%n\\\notag &\Rightarrow\ 1=a^{\varphi(n)}\%n\\\notag &\Rightarrow\ a^{\varphi(n)}\equiv1\pmod n \end{align} \]

posted @ 2022-05-26 21:49  Locked_Fog  阅读(347)  评论(0)    收藏  举报