Created
December 27, 2017 08:32
-
-
Save tamlt2704/9dc0bddd4a46bf59e09fcba11b276f7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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