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)

#include <stdio.h>
#include <math.h>

int main(void){
  int i = 2, j = 0, k, d, n, ncpy, s[10], count = 1;

  scanf("%d", &n);
  ncpy = n;
  while(ncpy != 1){
    if(ncpy % i == 0){
      while(ncpy % i == 0){
	ncpy /= i;
      }
      s[j++] = i;
      i++;
    }else if(i > sqrt(ncpy)){
      s[j++] = ncpy;
      break;
    }else{
      i++;
    }
  }

  for(i = 2; i < n; i++){
    d = 0;
    for(k = 0; k < j; k++){
      if(i % s[k] == 0){
	d++;
       	break;
      }
    }
    if(d == 0){
      count++;
    }
  }
  printf("%d\n", count);
  return 0;
}