Last active
August 29, 2015 14:08
-
-
Save Cee/3f416d9180707f91f8e2 to your computer and use it in GitHub Desktop.
Power
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
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