You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:欧拉函数 互质的概念理解:gcd(x,y)=1
|
|
|
|
|
* @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() {
|
|
|
|
|
for (int i = 1; i <= 10; i++)
|
|
|
|
|
cout << "i=" << i << " phi[" << i << "]=" << phi(i) << endl;
|
|
|
|
|
//以9为例,与9形成gcd(x,9)=1的x共有6个,分别是(1,2,4,5,7,8)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|