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
function isDivisibleRec ( x , a , b , n ) { if ( x > n ) return false ; if ( n % x == 0 ) return true ; return ( isDivisibleRec ( x * 10 + a , a , b , n ) || isDivisibleRec ( x * 10 + b , a , b , n ) ) ; } function isDivisible ( a , b , n ) { return isDivisibleRec ( a , a , b , n ) || isDivisibleRec ( b , a , b , n ) ; } let a = 3 , b = 5 , n = 53 ; if ( isDivisible ( a , b , n ) ) document . write ( " " ) ; else document . write ( " " ) ;