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

using System;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int j,count=0;
            if (n % 2 == 0) j = 2;
            else j = 1;
            for(int i = 1; i < n; i += j)
            {
                if (gcd(n%i, i) == 1) count++;
            }
            Console.WriteLine(count);
        }

        static int gcd(int a,int b)
        {
            int x = a;
            int y = b;
            int r;
            while(y != 0)
            {
                r = x % y;
                x = y;
                y = r;
            }
            return x;
        }
    }
}