import java.io.* ;
import java.util.* ;
import java.awt.Point ;
public class ListOfNaturalNumbers {
try {
while ( ! st.hasMoreTokens ( ) ) {
if ( s == null )
return null ;
}
return st.nextToken ( ) ;
return null ;
}
}
while ( true ) {
long N
= Long .
parseLong ( next
( ) ) ; if ( N == 0 ) {
break ;
}
out.println ( N == 1 ? 2 : phi( N) ) ;
}
//
out.flush ( ) ;
}
static long [ ] uniqueFactors( long N) {
ArrayList< Long> list = new ArrayList< Long> ( ) ;
if ( N% 2 == 0 ) {
list.add ( 2L) ;
while ( N% 2 == 0 ) N >>= 1 ;
}
long p = 3 ;
while ( p* p <= N) {
if ( N % p == 0 ) {
list.add ( p) ;
while ( N% p == 0 ) N /= p;
}
p += 2 ;
}
if ( N != 1 ) {
list.add ( N) ;
}
long [ ] ans = new long [ list.size ( ) ] ;
for ( int k = 0 ; k < list.size ( ) ; k++ ) ans[ k] = list.get ( k) ;
return ans;
}
static long phi( long N) {
long [ ] f = uniqueFactors( N) ;
for ( int i = 0 ; i < f.length ; i++ ) {
N /= f[ i] ;
N *= f[ i] - 1 ;
}
return N;
}
}
aW1wb3J0IGphdmEuaW8uKjsKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5hd3QuUG9pbnQ7CgpwdWJsaWMgY2xhc3MgTGlzdE9mTmF0dXJhbE51bWJlcnMgewoKCXN0YXRpYyBCdWZmZXJlZFJlYWRlciBiciA9IG5ldyBCdWZmZXJlZFJlYWRlcihuZXcgSW5wdXRTdHJlYW1SZWFkZXIoU3lzdGVtLmluKSk7CglzdGF0aWMgUHJpbnRXcml0ZXIgb3V0ID0gbmV3IFByaW50V3JpdGVyKG5ldyBCdWZmZXJlZE91dHB1dFN0cmVhbShTeXN0ZW0ub3V0KSk7CglzdGF0aWMgU3RyaW5nVG9rZW5pemVyIHN0ID0gbmV3IFN0cmluZ1Rva2VuaXplcigiIik7CgoJcHVibGljIHN0YXRpYyBTdHJpbmcgbmV4dCgpIHsKCQl0cnkJewoJCXdoaWxlICghc3QuaGFzTW9yZVRva2VucygpKSB7CgkJCVN0cmluZyBzID0gYnIucmVhZExpbmUoKTsKCQkJaWYgKHMgPT0gbnVsbCkKCQkJCXJldHVybiBudWxsOwoJCQlzdCA9IG5ldyBTdHJpbmdUb2tlbml6ZXIocyk7CgkJfQoJCXJldHVybiBzdC5uZXh0VG9rZW4oKTsKCQl9CWNhdGNoKEV4Y2VwdGlvbiBlKQl7CgkJCXJldHVybgludWxsOwoJCX0KCX0KCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFzZGEpIHRocm93cyBFeGNlcHRpb24gewogICAgICAgIHdoaWxlICAgKHRydWUpICB7CiAgICAgICAgICAgIGxvbmcgTiA9IExvbmcucGFyc2VMb25nKCBuZXh0KCkgKTsKICAgICAgICAgICAgaWYgKE4gPT0gMCkgewogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgb3V0LnByaW50bG4oIE4gPT0gMSA/IDIgOiBwaGkoTikgKTsKICAgICAgICB9CiAgICAgICAgLy8KICAgICAgICBvdXQuZmx1c2goKTsKICAgICAgICBTeXN0ZW0uZXhpdCgwKTsKICAgIH0KICAgIHN0YXRpYyBsb25nIFtdIHVuaXF1ZUZhY3RvcnMobG9uZyBOKSB7CiAgICAgICAgQXJyYXlMaXN0PExvbmc+IGxpc3QgPSBuZXcgQXJyYXlMaXN0PExvbmc+KCk7CgogICAgICAgIGlmIChOJTIgPT0gMCkgewogICAgICAgICAgICBsaXN0LmFkZCgyTCk7CiAgICAgICAgICAgIHdoaWxlICAgKE4lMiA9PSAwKSAgTiA+Pj0gMTsKICAgICAgICB9CgogICAgICAgIGxvbmcgcCA9IDM7CiAgICAgICAgd2hpbGUgICAocCpwIDw9IE4pICB7CiAgICAgICAgICAgIGlmIChOICUgcCA9PSAwKSB7CiAgICAgICAgICAgICAgICBsaXN0LmFkZChwKTsKICAgICAgICAgICAgICAgIHdoaWxlICAgKCBOJXAgPT0gMCApICAgIE4gLz0gcDsKICAgICAgICAgICAgfQogICAgICAgICAgICBwICs9IDI7CiAgICAgICAgfQogICAgICAgIGlmIChOICE9IDEpIHsKICAgICAgICAgICAgbGlzdC5hZGQoTik7CiAgICAgICAgfQoKICAgICAgICBsb25nIFtdIGFucyA9IG5ldyBsb25nIFtsaXN0LnNpemUoKV07CiAgICAgICAgZm9yIChpbnQgayA9IDA7IGsgPCBsaXN0LnNpemUoKTsgaysrKSAgIGFuc1trXSA9IGxpc3QuZ2V0KGspOwogICAgICAgIHJldHVybiAgYW5zOwogICAgfQogICAgc3RhdGljIGxvbmcgcGhpKGxvbmcgTikgICB7CiAgICAgICAgbG9uZ1tdIGYgPSB1bmlxdWVGYWN0b3JzKE4pOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgZi5sZW5ndGg7IGkrKykgewogICAgICAgICAgICAgICAgTiAvPSBmW2ldOwogICAgICAgICAgICAgICAgTiAqPSBmW2ldIC0gMTsKICAgICAgICAgICAgfQogICAgICAgIHJldHVybiBOOwogICAgfQoJCn0K