#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;
}
