Generate an array having sum of Euler Totient Function of all elements equal to N | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void constructArray ( int N ) { vector < int > ans ; for ( int i = 1 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { ans . push_back ( i ) ; if ( N != ( i * i ) ) { ans . push_back ( N / i ) ; } } } for ( auto it : ans ) { cout << it << " ▁ " ; } } int main ( ) { int N = 12 ; constructArray ( N ) ; return 0 ; }