import java.io.*;
import java.util.*;
import java.awt.Point;

public class ListOfNaturalNumbers {

	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	static StringTokenizer st = new StringTokenizer("");

	public static String next() {
		try	{
		while (!st.hasMoreTokens()) {
			String s = br.readLine();
			if (s == null)
				return null;
			st = new StringTokenizer(s);
		}
		return st.nextToken();
		}	catch(Exception e)	{
			return	null;
		}
	}
	public static void main(String[] asda) throws Exception {
        while   (true)  {
            long N = Long.parseLong( next() );
            if (N == 0) {
                break;
            }
            out.println( N == 1 ? 2 : phi(N) );
        }
        //
        out.flush();
        System.exit(0);
    }
    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;
    }
	
}
