#include <iostream>
using namespace std;
int main () {
int n, k;
while (cin >> n and n!=0) {
k = n;
for (int i = 2; i*i <= n; i++) {
if (n % i == 0) {
while (n % i == 0) {
n/= i;
}
k-=k/i;
}
}
if (n > 1) {
k-=k/n;
}
cout << k << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4gKCkgewoJaW50IG4sIGs7CgkKCXdoaWxlIChjaW4gPj4gbiBhbmQgbiE9MCkgewogICAJICAgIGsgPSBuOwoJICAgIGZvciAoaW50IGkgPSAyOyBpKmkgPD0gbjsgaSsrKSB7CgkgICAgICAgIGlmIChuICUgaSA9PSAwKSB7CgkgICAgICAgICAgICB3aGlsZSAobiAlIGkgPT0gMCkgewoJICAgICAgICAgICAgCW4vPSBpOwoJICAgICAgICAgICAgfQoJICAgICAgICAgICAgay09ay9pOwoJICAgICAgICB9CgkgICAgICAgIAoJICAgIH0KCSAgICAKCSAgICBpZiAobiA+IDEpIHsKCSAgICAJay09ay9uOwoJICAgIH0KCSAgICAKCSAgICBjb3V0IDw8IGsgPDwgZW5kbDsKCSAgICAKICAgIH0KICAgIHJldHVybiAwOyAgIAp9Cg==