Check if N is divisible by a number which is composed of the digits from the set { A , B } | Function to check whether n is divisible by a number whose digits are either a or b ; base condition ; recursive call ; Check for all numbers beginning with ' a ' or 'b ; Driver Code
def isDivisibleRec ( x , a , b , n ) : NEW_LINE INDENT if ( x > n ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( n % x == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT return ( isDivisibleRec ( x * 10 + a , a , b , n ) or isDivisibleRec ( x * 10 + b , a , b , n ) ) NEW_LINE DEDENT def isDivisible ( a , b , n ) : NEW_LINE ' NEW_LINE INDENT return ( isDivisibleRec ( a , a , b , n ) or isDivisibleRec ( b , a , b , n ) ) NEW_LINE DEDENT a = 3 ; b = 5 ; n = 53 ; NEW_LINE if ( isDivisible ( a , b , n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT