Skip to content

Instantly share code, notes, and snippets.

@LungZeno
Forked from timshen91/main.cpp
Last active December 15, 2015 10:19
Show Gist options
  • Save LungZeno/5244678 to your computer and use it in GitHub Desktop.
Save LungZeno/5244678 to your computer and use it in GitHub Desktop.
#include <cstdio>
int div(int a, int b) {
if (b == 0) {
return -1;
}
int acc = 0;
int c = 1;
while(!(a < b)) {
b <<= 1;
c <<= 1;
}
while(c > 1) {
c >>= 1;
b >>= 1;
if(a >= b) {
acc += c;
a -= b;
}
}
return acc;
}
int main() {
printf("%d\n", div(20000000, 9));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment