Sum of product of all subsets formed by only divisors of N | Java 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
import java . util . * ; class GFG { static int GetSum ( int n ) { Vector < Integer > divisors = new Vector < Integer > ( ) ; for ( int i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { divisors . add ( i ) ; if ( i != n / i ) { divisors . add ( n / i ) ; } } } int ans = 1 ; for ( int i = 0 ; i < divisors . size ( ) ; i ++ ) { ans *= ( divisors . get ( i ) + 1 ) ; } ans = ans - 1 ; return ans ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . println ( GetSum ( N ) ) ; } }