Skip to content

Instantly share code, notes, and snippets.

@Cee
Last active August 29, 2015 14:08
Show Gist options
  • Save Cee/3f416d9180707f91f8e2 to your computer and use it in GitHub Desktop.
Save Cee/3f416d9180707f91f8e2 to your computer and use it in GitHub Desktop.
Power
int power(int n, int k) {
if (k == 0) return 1;
if (k == 1) return n;
int ret = power(n, k >> 1);
return (k & 1)
? ret * ret * n //odd
: ret * ret; //even
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment