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: Accepted)

using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Trim().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static List<long> primefactorize(long n)
        {
            var primes = new List<long>();
            for (var i = 2; i * i <= n; ++i)
            {
                if (n % i == 0)
                {
                    while (n % i == 0)
                    {
                        primes.Add(i);
                        n /= i;
                    }
                }
            }
            if (n != 1) primes.Add(n);
            return primes;
        }
        static long eulersPhi(long n)
        {
            foreach (var p in primefactorize(n).Distinct())
                n -= n / p;
            return n;
        }
        static void Main(string[] args)
        {
            var n = Sarray()[0];
            var ps = primefactorize(n).Distinct();
            var ans = n;
            foreach (var p in ps)
                ans = ans - ans / p;
            WriteLine(ans);
        }
    }
}