Sum of product of all subsets formed by only divisors of N | C ++ program to find the sum of product of all the 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int GetSum ( int n ) { vector < int > divisors ; for ( int i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { divisors . push_back ( i ) ; if ( i != n / i ) { divisors . push_back ( n / i ) ; } } } int ans = 1 ; for ( auto i : divisors ) { ans *= ( i + 1 ) ; } ans = ans - 1 ; return ans ; } int main ( ) { int N = 4 ; cout << GetSum ( N ) << endl ; }