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 Haskell (judge verdict: Time Limit Exceeded)

main = do
  n <- readLn
  print $ length $ totient n

phi :: Int -> [Int]
phi n = 1 : [ x | x <- [2..sqr], gcd n x == 1] ++ [ y | x <- [2..sqr], let y = n `div` x, gcd n x == 1]
  where sqr = floor $ sqrt $ fromIntegral n
--phi n = [x | x <- [2..n], gcd n x == 1 || gcd n x == x]

totient :: Int -> [Int]
totient 1 = [1]
totient a = filter (coprime a) [1..a-1]
 where coprime a b = gcd a b == 1