当前位置:网站首页>Mathematical knowledge: Euler function - Euler function

Mathematical knowledge: Euler function - Euler function

2022-06-23 07:45:00 Fight! Sao Nian!

subject :AcWing 873. Euler function
Given n A positive integer ai, Please find the Euler function of each number .

The definition of Euler function
1∼N China and N The number of Coprime numbers is called Euler function , Write it down as ϕ(N).
If in the basic theorem of arithmetic ,N=p1a1p2a2…pmam, be :
ϕ(N) = N×(p1−1)/p1×(p2−1)/p2×…×(pm−1)/pm
Input format
The first line contains integers n.

Next n That's ok , Each line contains a positive integer ai.

Output format
The output, n That's ok , Each line outputs a positive integer ai The Euler function of .

Data range
1≤n≤100,
1≤ai≤2×109

sample input :

3
3
6
8

sample output :

2
2
4

#include <iostream>

using namespace std;

int main()
{
    
    int n;
    cin>>n;
    while(n--)
    {
    
        int a;
        cin>>a;
        int res=a;
        for(int i=2;i<=a/i;i++)
            if(a%i==0)
            {
    
                res=res/i*(i-1);
                while(a%i==0)a/=i;
            }
        if(a>1)res=res/a*(a-1);
        cout<<res<<endl;
    }
    return 0;
}
原网站

版权声明
本文为[Fight! Sao Nian!]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230700516540.html