Euler 's Totient function for all numbers smaller than or equal to n | Javascript program for the above approach ; driver code
function Euler_totient_function ( n ) { let result = 1 ; for ( let i = 2 ; i * i <= n ; i ++ ) { let c = 0 ; if ( n % i == 0 ) { while ( n % i == 0 ) { c ++ ; n = parseInt ( n / i ) ; } } if ( c > 0 ) { let power = Math . pow ( i , c - 1 ) ; let sm = Math . pow ( i , c - 1 ) * ( i - 1 ) ; result *= sm ; } } if ( n > 1 ) { result *= ( n - 1 ) ; } return result ; } for ( let i = 1 ; i < 13 ; i ++ ) { document . write ( " " + i + " " ) ; document . write ( Euler_totient_function ( i ) + " " ) ; }