Skip to content

Instantly share code, notes, and snippets.

@psych0der
Created August 22, 2013 16:56
Show Gist options
  • Save psych0der/6309906 to your computer and use it in GitHub Desktop.
Save psych0der/6309906 to your computer and use it in GitHub Desktop.
fast exponential calculation using repeated squaring
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