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: Wrong Answer)

import math

def eulers_phi_function(n):
    s = math.sqrt(n)
    x = n
    rst = n
    for y in range(2, math.ceil(s)):
        if x == 1: break
        while True:
            if x%y == 0:
                rst *= 1 - 1/y
                while x%y == 0:
                    x = x/y
            else:
                break
    if rst == n:
        rst = 2
    elif x > s:
        rst *= 1 - 1/x
    return int(rst)

n = int(input())
print(eulers_phi_function(n))