Last active
December 30, 2015 05:18
-
-
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
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
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