欧拉函数:

  φ(p)表示小于p的正整数中与p互质的数的个数,称作欧拉函数。

  求单个数的欧拉函数时可以利用逆元&欧拉函数来求

  其中pi为p分解出的质因数,ki表示该质因数的指数

  代码:

#include<cstdio>
#include<iostream>
using namespace std;
int phi[100];
int Eurl(int x)
{
    int ans=1;
    for(int i=2;i*i<=x;++i)
    {
        if(x%i==0)
        {
            x/=i;
            ans*=i-1;
        }
        while(x%i==0)
        {
            x/=i;
            ans*=i;
        }
    }
    if(x!=1) ans*=(x-1);
    return ans;
}
int main()
{
    int n=1;
    while(1)
    {
        scanf("%d",&n);
        if(!n) break;
         printf("%d\n",Eurl(n));
    }
    return 0;
}
单个欧拉函数

相关文章:

  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2021-08-31
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-10
  • 2021-10-05
  • 2021-11-01
  • 2022-12-23
相关资源
相似解决方案