Generate an array having sum of Euler Totient Function of all elements equal to N | 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 ; Prvar the resultant array ; Driver Code ; Function Call
function constructArray ( N ) { var ans = [ ] ; for ( var i = 1 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { ans . push ( i ) ; if ( N != ( i * i ) ) { ans . push ( N / i ) ; } } } document . write ( ans ) ; } var N = 12 ; constructArray ( N ) ;