Skip to content

Instantly share code, notes, and snippets.

@andrei512
Created October 16, 2012 11:47
Show Gist options
  • Save andrei512/3898822 to your computer and use it in GitHub Desktop.
Save andrei512/3898822 to your computer and use it in GitHub Desktop.
a^b -> O(log(b))
int put(int a, int b) {
if (b == 0) {
return 1;
}
if (b == 1) {
return a;
}
int ret = put(a, b/2);
return ret * ret * (b % 2 ? a : 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment