You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
533 B
C++
24 lines
533 B
C++
#define _CRT_SECURE_NO_WARNINGS
|
|
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
|
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
int phi(int x)
|
|
{
|
|
set<char, int> S;
|
|
int ret = x;
|
|
for (long long i = 2; i * i <= x; i++)
|
|
if (x % i == 0)
|
|
{
|
|
ret = ret / i * (i - 1); //ÖÐÎÄ×¢ÊÍ
|
|
while (x % i == 0) x /= i;
|
|
}
|
|
if (x > 1) ret = ret / x * (x - 1);
|
|
return ret;
|
|
}
|
|
int main()
|
|
{
|
|
int n;
|
|
while (scanf("%d", &n), n) printf("%d\n", phi(n));
|
|
return 0;
|
|
}
|