Skip to content

Instantly share code, notes, and snippets.

@tamlt2704
Created December 27, 2017 08:32
Show Gist options
  • Select an option

  • Save tamlt2704/9dc0bddd4a46bf59e09fcba11b276f7c to your computer and use it in GitHub Desktop.

Select an option

Save tamlt2704/9dc0bddd4a46bf59e09fcba11b276f7c to your computer and use it in GitHub Desktop.
a = 1000001
b = 2
def mdivide(a, b):
i = 1
t1 = b
while t1 < a:
if (t1<<1) < a:
t1<<=1
i<<=1
else:
t1+=b
i+=1
t = 1 if a - t1 else 0
return i - 1*t, a - t1 + b*t
print mdivide(18, 20)
print mdivide(10, 2)
print mdivide(1000001, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment