Skip to content

Instantly share code, notes, and snippets.

@clementi
Created February 16, 2011 02:53
Show Gist options
  • Save clementi/828774 to your computer and use it in GitHub Desktop.
Save clementi/828774 to your computer and use it in GitHub Desktop.
Project Euler Problem #97 Solution
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