Generate an array having sum of Euler Totient Function of all elements equal to N | Java program for the above approach ; Function to construct the array such the sum of values of Euler Totient functions of all array elements is N ; Stores the resultant array ; Find divisors in sqrt ( N ) ; If N is divisible by i ; Push the current divisor ; If N is not a perfect square ; Push the second divisor ; Print the resultant array ; Driver Code ; Function Call
import java . util . * ; class GFG { static void constructArray ( int N ) { ArrayList < Integer > ans = new ArrayList < Integer > ( ) ; for ( int i = 1 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { ans . add ( i ) ; if ( N != ( i * i ) ) { ans . add ( N / i ) ; } } } for ( int it : ans ) { System . out . print ( it + " ▁ " ) ; } } public static void main ( String [ ] args ) { int N = 12 ; constructArray ( N ) ; } }