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 Ruby (judge verdict: Accepted)

require 'prime'
def phi_func(n)
    factors=n.prime_division
    fct=factors.pop
    phi=(fct[0]-1)*fct[0]**(fct[1]-1)
    if factors.size.zero?
        return phi
    else
        m=Prime.int_from_prime_division(factors)
        return phi*phi_func(m)
    end
end

n=gets.to_i
p phi_func(n)