Suppose we have a number n. We have another two numbers a and b. We have to check whether we can generate a number using a and b that divides n.
So, if the input is like n = 115, a = 3, b = 2, then the output will be True as 115 is divisible by 23 which is made of 2 and 3.
To solve this, we will follow these steps −
if n is divisible by temp, then
Let us see the following implementation to get better understanding −
def util(temp, a, b, n): if temp > n: return False if n % temp == 0: return True return util(temp * 10 + a, a, b, n) or util(temp * 10 + b, a, b, n) def solve(n, a, b): return util(a, a, b, n) or util(b, a, b, n) n = 115 a = 3 b = 2 print(solve(n, a, b))
115, 2, 3