Created
December 9, 2015 13:55
-
-
Save mrahul17/188079f3b3f021f699ef to your computer and use it in GitHub Desktop.
Exponentiation by squaring
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 ipow(int base, int exp) | |
| { | |
| int result = 1; | |
| while (exp) | |
| { | |
| if (exp & 1) | |
| result *= base; | |
| exp >>= 1; | |
| base *= base; | |
| } | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment