Created
November 27, 2011 14:46
-
-
Save dmalikov/1397648 to your computer and use it in GitHub Desktop.
Project Euler 188 (0.3 s)
This file contains hidden or 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
moddule = 10 ^ 8 | |
lastDigits x = x `mod` moddule | |
fastPow :: Integer -> Integer -> Integer -> Integer | |
fastPow base 1 m = mod base m | |
fastPow base pow m | even pow = mod ((fastPow base (div pow 2) m) ^ 2) m | |
| odd pow = mod ((fastPow base (div (pow-1) 2) m) ^ 2 * base) m | |
tetration a 1 = lastDigits a | |
tetration a k = lastDigits ( fastPow a' (tetration a' k') moddule) | |
where a' = lastDigits a | |
k' = lastDigits k - 1 | |
main = print $ tetration 1777 1855 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment