Created
December 7, 2018 08:38
-
-
Save leftrk/031a0b41e4ea0ee5383bf3870f01ab84 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
long long pow(long long x, int n) { | |
if (n == 0) | |
return 1; | |
if (n == 1) | |
return x; | |
if (n & 0x1) | |
return pow(x * x, n / 2) * x; | |
else | |
return pow(x * x, n / 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment