Skip to content

Instantly share code, notes, and snippets.

@mochja
Last active December 30, 2015 05:18
Show Gist options
  • Save mochja/7781397 to your computer and use it in GitHub Desktop.
Save mochja/7781397 to your computer and use it in GitHub Desktop.
Zenit 3 987654327 2 5 vypocita zvysok velkeho exponencialneho cisla. - http://stackoverflow.com/questions/5989429/pow-and-mod-function-optimization
uint64_t expmod(uint64_t base, uint64_t exp, uint64_t mod ){
if (exp == 0) return 1;
return (exp % 2 == 0) ? ( ((uint64_t) pow( expmod( base, (exp / 2), mod), 2) ) % mod ) : ((base * expmod( base, (exp - 1), mod)) % mod);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment