Created
August 22, 2013 16:56
-
-
Save psych0der/6309906 to your computer and use it in GitHub Desktop.
fast exponential calculation using repeated squaring
This file contains 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 expo(int a, int b){ | |
int result = 1; | |
while (b) | |
{ | |
if (b%2==1) | |
{ | |
result *= a; | |
} | |
b /= 2; | |
a *= a; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment