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: Memory Limit Exceeded)

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<fstream>
#include <map>
#include<math.h>
#include <bitset>
#include <set>
using namespace std;

int main(){
	std::istream & c_in = cin;

	map<int, int> t;
	int n;
	c_in >> n;
	int a = n;
	int i = 2;
	while (a != 1)
	{
		if ((a % i) == 0) {
			a /= i;
			t[i]++;
			continue;
		}
		i += 1 + (i & 1);
		if (i > ::sqrt(a))
		{
			t[a]++;
			break;
		}
	}

	const long N = 1000000000;
	std::bitset<N + 1> *pflg = new bitset < N + 1>();
	std::bitset<N + 1> & flg = *pflg;
	flg.set(0);
	for (map<int, int>::iterator r = t.begin(); r != t.end(); ++r)
	{
		for (int i = 1; i*r->first < n; ++i)
		{
			//flg.reset(i*r->first);
			flg.set(i*r->first);
		}
	}
	cout << n - flg.count() << endl;
}