ETF - Euler Totient Function

In number theory, the totient φ of a positive integer n is defined to be the number of positive integers less than or equal to n that are coprime to n.

Given an integer n (1 <= n <= 10^6). Compute the value of the totient φ.


First line contains an integer T, the number of test cases. (T <= 20000)

T following lines, each contains an integer n.


T lines, one for the result of each test case.




hide comments
jayharsh: 2017-08-12 14:59:14

AC in One Go ! 0.03 Sec........

dangerous321: 2017-07-04 09:19:14

AC in one go in C
But getting TLE in JAVA

mehul_sri: 2017-06-29 12:19:29

I don't know why but using int gave me wa. Use long long int.

themast3r: 2017-06-17 23:24:47

Those who need help, first read this : and then this : . You are enough equipped with knowledge know to tackle this problem.

shauryauppal: 2017-06-06 00:10:24

Space Complexity also very limited,I was caching my answer once calculated with (array / map tried both) but I got wrong answer all the time.
As soon as I removed the caching part got AC.

calculator to verify your answer->

ode_to_code: 2017-05-31 09:45:25

can anyone post a link for the most efficient fast i/o code in java . i have tried ones given on geek for geeks and hacker earth but still get tle. have faced the same problem in many questions. please its a humble request on behalf of all java noobs .

hk_visact: 2017-05-25 13:46:53

TLE in java... any way to solve this in java?

v_ns: 2017-03-31 16:38:13

Take help from here:-

dinkar: 2017-03-26 09:03:28

Can anybody help me how to solve this problem using Java.
I have submitted same logic in c++ and submission is accepted but Java gives TLE.

Any suggestions to submit in Java ?

rohit9934: 2017-03-07 18:38:23

See Wikipedia Article for Euler Totient Function and Try to develop your own code,If you again stuck, check out the Topcoder Tutorial for the same. 0.07 sec with c++.

Added by:Race with time
Time limit:0.161s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET