Super Niven Numbers | 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 store digits of N ; Driver code
def isDivBySubsetSums ( arr , num ) : NEW_LINE INDENT n = len ( arr ) NEW_LINE total = 1 << n NEW_LINE i = 0 NEW_LINE while i < total : NEW_LINE INDENT sum = 0 NEW_LINE j = 0 NEW_LINE while j < n : NEW_LINE INDENT if ( i & ( 1 << j ) ) : NEW_LINE INDENT sum += arr [ j ] NEW_LINE DEDENT j += 1 NEW_LINE DEDENT if ( sum != 0 ) and ( num % sum != 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return True NEW_LINE DEDENT def isSuperNivenNum ( n ) : NEW_LINE INDENT temp = n NEW_LINE digits = [ ] NEW_LINE while ( n > 1 ) : NEW_LINE INDENT digit = int ( n ) % 10 NEW_LINE digits . append ( digit ) NEW_LINE n = n / 10 NEW_LINE DEDENT return isDivBySubsetSums ( digits , temp ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 500 NEW_LINE if isSuperNivenNum ( n ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT