I am using Python 3 and am practicing recursion. Here’s the problem.
Here’s my code:
from math import floor, log10 def square_packing(length, width): if length == 0 or width == 0: return 0 min_side = min(length, width) power = floor(log10(min_side) / log10(2)) side = 2 ** power max_side = max(length, width) m = max_side // side x = max_side % side y = min_side % side return m + square_packing(x, side) + square_packing(m * side, y) + square_packing(x, y) a = eval(input()) b = eval(input()) print(square_packing(a, b))
It prints the correct output for all of the inputs except a 9999 x 8888 floor. Is there a problem in my code or does the question has a typo error?