Problem:
Euler's Phi Function

For given integer n, count the totatives of n, that is, the positive integers less than or equal to n that are relatively prime to n.

Input

n

An integer n (1 ≤ n ≤ 1000000000).

Output

The number of totatives in a line.

Sample Input 1

6

Sample Output 1

2

Sample Input 2

1000000

Sample Output 2

400000

Solution in Python3 (judge verdict: Accepted)

def main():
    N = int(input())

    def prime_factorize(n):
        res = []
        for i in range(2, n+1):
            if i*i > n:
                break
            if n % i != 0:
                continue
            ex = 0
            while n % i == 0:
                ex += 1
                n //= i
            res.append((i, ex))
        if n != 1:
            res.append((n, 1))
        return res

    def euler_totient_function(n):
        # オイラーのφ関数
        # 1からnのうち，nと互いに素な整数の個数
        pf = prime_factorize(n)
        res = n
        for p, _ in pf:
            res *= p-1
            res //= p
        return res

    print(euler_totient_function(N))


if __name__ == '__main__':
    main()