Super Niven Numbers | Java implementation to check if a number is Super Niven Number or not . ; Checks if sums of all subsets of digits array divides the number N ; to calculate length of array arr ; There are totoal 2 ^ n subsets ; Consider all numbers from 0 to 2 ^ n - 1 ; Consider binary representation of current i to decide which elements to pick . ; check sum of picked elements . ; Function to check if a number is a super - niven number ; to stor digits of N ; Driver code
import java . util . * ; class GFG { static boolean isDivBySubsetSums ( Vector < Integer > arr , int num ) { int n = arr . size ( ) ; long total = 1 << n ; for ( long i = 0 ; i < total ; i ++ ) { long sum = 0 ; for ( int j = 0 ; j < n ; j ++ ) if ( ( i & ( 1 << j ) ) > 0 ) sum += arr . get ( j ) ; if ( sum != 0 && num % sum != 0 ) return false ; } return true ; } static boolean isSuperNivenNum ( int n ) { int temp = n ; Vector < Integer > digits = new Vector < Integer > ( ) ; while ( n != 0 ) { int digit = n % 10 ; digits . add ( digit ) ; n = n / 10 ; } return isDivBySubsetSums ( digits , temp ) ; } public static void main ( String [ ] args ) { int n = 500 ; if ( isSuperNivenNum ( n ) ) System . out . print ( " yes " ) ; else System . out . print ( " No " ) ; } }