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.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        bool[] b = new bool[100000];
        int N = int.Parse(Console.ReadLine());
        int n = N;
        List<int> p = new List<int>();
        for(int i=2;i<100000;i++){
            if(!b[i]){
                for(int j=i;j<100000;j+=i){
                    b[j] = true;
                }
                if(n % i == 0){
                    p.Add(i);
                }
                while(n % i == 0){
                    n /= i;
                }
            }
        }
        if(n != 1){
            p.Add(n);
        }
        int C = p.Count;
        long count = 0;
        for(int i=0;i<1<<C;i++){
            int c = 0;
            int num = 1;
            for(int j=0;j<C;j++){
                if((i & (1 << j)) != 0){
                    c++;
                    num *= p[j];
                }
            }
            if(c % 2 == 0){
                count += N/num; 
            }
            else{
                count -= N/num;
            }
        }
        sb.Append(count+"\n");
    }
}