Created
February 16, 2011 02:53
-
-
Save clementi/828774 to your computer and use it in GitHub Desktop.
Project Euler Problem #97 Solution
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
def is_even(n): | |
return n % 2 == 0 | |
def mod_exp(base, exponent, modulus): | |
if exponent == 0: | |
return 1 | |
temp = mod_exp(base, exponent / 2, modulus) | |
if is_even(exponent): | |
return (temp ** 2) % modulus | |
return base * (temp ** 2) % modulus | |
value = 28433 * mod_exp(2, 7830457, 10 ** 10) + 1 | |
print str(value)[-10:] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment