Euler 's Totient function for all numbers smaller than or equal to n | Java program for the above approach ; Driver code
import java . io . * ; class GFG { static long Euler_totient_function ( long n ) { long result = 1 ; for ( long i = 2 ; i * i <= n ; i ++ ) { long c = 0 ; if ( n % i == 0 ) { while ( n % i == 0 ) { c ++ ; n /= i ; } } if ( c > 0 ) { long power = ( long ) Math . pow ( i , c - 1 ) ; long sm = ( long ) Math . pow ( i , c - 1 ) * ( i - 1 ) ; result *= sm ; } } if ( n > 1 ) { result *= ( n - 1 ) ; } return result ; } public static void main ( String [ ] args ) { for ( long i = 1 ; i < 13 ; i ++ ) { System . out . print ( " Euler _ totient _ function ( " + i + " ) : ▁ " ) ; System . out . println ( Euler_totient_function ( i ) ) ; } } }