def divide(x, y): """ Input: Two non-negative integers x and y, where y>=1. Output: The quotient and remainder when x is divided by y.""" if x == 0: return 0, 0 q, r = divide(x // 2, y) # max recursive calls: q, r = 2 * q, 2 * r # number of bits in x if x % 2 == 1: r = r + 1 if r >= y: # note that all of the multiplications q, r = q + 1, r - y # and divisions are by 2: return q, r # simple bit shifts print (divide(19, 4)) print (divide(1445, 12)) print (divide(4, 19)) print (divide(76, 19))