#include <stdio.h> #include <math.h> #define MAX (5000000) bool bPrime[MAX];//false表示素数
void InitPrime() { bPrime[0] = bPrime[1] = true; int nMax = sqrt((double)MAX) + 1; for (int i = 2; i <= nMax; ++i) { if (!bPrime[i]) for (int j = i * 2; j < MAX; j += i) { bPrime[j] = true; } } }
bool IsPrime(int nN) { if (nN < MAX) { return !bPrime[nN]; } else { int nMax = sqrt((double)nN) + 1; for (int i = 2; i <= nMax; ++i) { if (nN % i == 0) { return false; } } return true; } }
int main() { int nN;
InitPrime(); while (scanf("%d", &nN), nN) { if (nN == 1) { printf("0\n"); continue; } int nAns = 1; for (int i = 2; i <= nN; ++i) { if (IsPrime(nN)) { nAns *= nN - 1; break; } if (nN % i == 0) { nAns *= i - 1; nN /= i; while (nN % i == 0) { nAns *= i; nN /= i; } } } printf("%d\n", nAns); }