25 lines
454 B
C++
25 lines
454 B
C++
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
/**
|
|
* 功能:欧拉函数
|
|
* @param x
|
|
* @return
|
|
*/
|
|
int phi(int x) {
|
|
int res = x;
|
|
for (int i = 2; i <= x / i; i++)
|
|
if (x % i == 0) {
|
|
res = res / i * (i - 1);
|
|
while (x % i == 0) x /= i;
|
|
}
|
|
if (x > 1) res = res / x * (x - 1);
|
|
return res;
|
|
}
|
|
|
|
int main() {
|
|
cout << phi(2) << endl;
|
|
cout << phi(8) << endl;
|
|
return 0;
|
|
} |