Suppose, we are given a number and we have to check whether the number is divisible by 17.
So, if the input is like 99943, then the output will be Divisible.
We will solve this problem using the repeated subtraction method, where we extract the last digit of the number and subtract it 5 times from the number until we get a two-digit number that is divisible by 17.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def solve(number) : while(number // 100) : last_digit = number % 10 number //= 10 number -= last_digit * 5 return (number % 17 == 0) number = 99943 if solve(number) : print("Divisible") else : print("Not Divisible")