Perfect Digital Invariants number | Function to find the sum of divisors ; Function to check whether the given number is Perfect Digital Invariant number or not ; For each digit in temp ; If satisfies Perfect Digital Invariant condition ; If sum exceeds n , then not possible ; Given Number N ; Function Call
def power ( x , y ) : NEW_LINE INDENT if ( y == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( y % 2 == 0 ) : NEW_LINE INDENT return ( power ( x , y // 2 ) * power ( x , y // 2 ) ) NEW_LINE DEDENT return ( x * power ( x , y // 2 ) * power ( x , y // 2 ) ) NEW_LINE DEDENT def isPerfectDigitalInvariant ( x ) : NEW_LINE INDENT fixed_power = 0 NEW_LINE while True : NEW_LINE INDENT fixed_power += 1 NEW_LINE temp = x NEW_LINE summ = 0 NEW_LINE while ( temp ) : NEW_LINE INDENT r = temp % 10 NEW_LINE summ = summ + power ( r , fixed_power ) NEW_LINE temp = temp // 10 NEW_LINE DEDENT if ( summ == x ) : NEW_LINE INDENT return ( True ) NEW_LINE DEDENT if ( summ > x ) : NEW_LINE INDENT return ( False ) NEW_LINE DEDENT DEDENT DEDENT N = 4150 NEW_LINE if ( isPerfectDigitalInvariant ( N ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT