Count all N digit numbers whose digits are multiple of X | Function to calculate x ^ n using binary - exponentiation ; Stores the resultant power ; Stores the value of x ^ ( n / 2 ) ; Function to count aN - digit numbers whose digits are multiples of x ; Count adigits which are multiples of x ; Check if current number is a multiple of X ; Increase count of multiples ; Check if it 's a 1 digit number ; Count the total numbers ; Return the total numbers ; Driver Code ; Given N and X ; Function call
def power ( x , n ) : NEW_LINE INDENT temp = [ ] NEW_LINE if ( n == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT temp = power ( x , n // 2 ) NEW_LINE if ( n % 2 == 0 ) : NEW_LINE INDENT return temp * temp NEW_LINE DEDENT else : NEW_LINE INDENT return x * temp * temp NEW_LINE DEDENT DEDENT def count_Total_Numbers ( n , x ) : NEW_LINE INDENT total , multiples = 0 , 0 NEW_LINE for i in range ( 10 ) : NEW_LINE INDENT if ( i % x == 0 ) : NEW_LINE INDENT multiples += 1 NEW_LINE DEDENT DEDENT if ( n == 1 ) : NEW_LINE INDENT return multiples NEW_LINE DEDENT total = ( ( multiples - 1 ) * power ( multiples , n - 1 ) ) NEW_LINE return total NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 1 NEW_LINE X = 3 NEW_LINE print ( count_Total_Numbers ( N , X ) ) NEW_LINE DEDENT