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
< ? php 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 ) ; } $ a = 3 ; $ b = 5 ; $ n = 53 ; if ( isDivisible ( $ a , $ b , $ n ) ) echo " Yes " ; else echo " No " ;