标签:-- csharp main fun 代码 class logs jpg 质因数
今天我来分享一下如何利用素数分解定理求解与n互质的数的个数。

下面是代码
#include<bits/stdc++.h>
using namespace std;
long long fun(int x)
{
long long ans=x;
int t=sqrt(x);
int cnt;
for(int i=2;i<=t;i++)
{
cnt=0;
while(x%i==0)
{
x/=i;
cnt++;
}
if(cnt) ans=ans*(i-1)/i;
}
if(x>1) ans=ans*(x-1)/x;
return ans;
}
int main()
{
int n;
cin>>n;
int t;
while(n--)
{
cin>>t;
printf("%lld\n",fun(t));
}
return 0;
}
标签:-- csharp main fun 代码 class logs jpg 质因数
原文地址:https://www.cnblogs.com/AC--Dream/p/14702025.html