Sum of product of all subsets formed by only divisors of N | Function to find the sum of product of all the subsets formed by only divisors of N ; Vector to store all the divisors of n ; Loop to find out the divisors of N ; Both ' i ' and ' n / i ' are the divisors of n ; Check if ' i ' and ' n / i ' are equal or not ; Calculating the answer ; Excluding the value of the empty set ; Driver Code
function GetSum ( n ) { var divisors = [ ] ; for ( var i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { divisors . push ( i ) ; if ( i != n / i ) { divisors . push ( n / i ) ; } } } var ans = 1 ; for ( var i = 0 ; i < divisors . length ; i ++ ) { ans *= ( divisors [ i ] + 1 ) ; } ans = ans - 1 ; return ans ; } var N = 4 ; document . write ( GetSum ( N ) ) ;