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

using System;
using System.Collections.Generic;

namespace NTL1_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var P = new List<int>();
            eratos(P, (int)(Math.Sqrt(n)));
            var L = new List<int>();
            for (int i = 0; i < P.Count; i++)
            {
                if (n % P[i] == 0)
                {
                    L.Add(P[i]);
                }
            }
            if (L.Count == 0)
            {
                L.Add(n);
            }
            int ans = n;
            foreach (var s in L)
            {
                ans = ans - ans / s;
            }
            Console.WriteLine(ans);
        }
        //2???n?????§????´???°????????????(n>=2)
        static void eratos(List<int> P, int n)
        {
            var a = new bool[n + 1];
            a[0] = a[1] = true;
            int i;
            for (i = 2; i * i <= n; i++)
            {
                if (!a[i])
                {
                    P.Add(i);
                    int j = i << 1;
                    while (j <= n)
                    {
                        a[j] = true;
                        j = j + i;
                    }
                }
            }
            for (; i <= n; i++) if (!a[i]) P.Add(i);
        }

    }
}