

You are given an integer 'N'. Your task is to count the number of integers between 1 and 'N' both inclusive which are coprime to 'N'.
Note:Two numbers are coprime if their greatest common divisor(GCD) is 1.
Here, 1 is considered to be coprime to any number.
For Example:
If the given integer is 9, then the answer would be 6 Because there are six numbers between 1 and 9 both inclusive which are coprime to 9 i.e 1, 2, 4, 5, 7, and 8.
The first line of input contains an integer 'T' representing the number of test cases or queries to be processed.
Then the test case follows.
The only line of each test case contains an integer 'N'.
Output Format:
For each test case, print a single line containing a single integer denoting the total numbers of integers between 1 and 'N'(both inclusive) which are coprime to 'N', in a single line.
The output of each test case will be printed in a separate line.
Note:
You don't have to print anything. It has already been taken care of. Just implement the function.
1 <= T <= 100
1 <= N <= 10 ^ 9
Time Limit: 1 sec.
2
1
4
1
2
For the first test case, there is only one number which is coprime to 1 i.e 1 itself.
For the second test case, there are only two numbers between 1 and 4(both inclusive) which are coprime to 4 i.e 1 and 3.
2
12
21
4
12
For the first test case, there are four numbers between 1 and 12(both inclusive) which are coprime to 12 i.e 1, 5, 7,11.
Think of a solution to use Euler’s product formula.
The better solution is to use Euler’s product formula which states that the total number of integers between 1 and N - 1 inclusive which are coprime to N can be found using this formula Euler Product Formula N * (1 - (1 / p1)) * (1 - (1 / p2)) *.......* (1 - (1 / pk)) where p1,p2...pk are the prime factors of N.
So now the problem is to find all the prime factors and use the above formula.
To find the prime factors and count the number of integers between 1 and N which are coprime to N below are the steps.
Steps:
O(sqrt(N)), where ‘N’ is the given integer.
In the worst case, finding all prime factors of ‘N’ takes sqrt(N) time. Hence overall complexity will be O(sqrt(N)).
O(1).
In the worst-case, only constant extra space is required.