Problem title
Difficulty
Avg time to solve

Data Structure Supporting Insert Delete And GetRandom
Easy
15 mins
Permutation In String
Hard
20 mins
Maximum number in K swaps
Hard
15 mins
Check if the door is open or closed
Easy
10 mins
Minimum Sum Subarray
Easy
15 mins
Add Two Fractions
Easy
10 mins
Matrix Chain Multiplication
Easy
--
Largest Prime Factor
Easy
15 mins
Palindrome Partitioning ll
Moderate
15 mins
Longest Common Subsequence
Moderate
--
3

Euler’s Totient Function

Difficulty: EASY
Contributed By
Ashwani |Level 1
Avg. time to solve
15 min
Success Rate
90%

Problem Statement

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.
Input Format:
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.     
Constraints:
1 <= T <= 100
1 <= N <= 10 ^ 9

Time Limit: 1 sec.
Sample Input 1:
2
1
4
Sample Output 1:
1
2
Explanation for Sample 1:
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.
Sample Input 2:
2
12
21
Sample Output 2:
4
12
Explanation for Sample 2:
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.
Reset Code
Full screen
copy-code
Console