Created
August 4, 2018 07:17
-
-
Save ihainan/41b13eabbb38b0b3f4a98281991d384f to your computer and use it in GitHub Desktop.
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
object Solution { | |
def powMod(x: Int, y: Int, mod: Int): Int = { | |
if (y == 0) 1 | |
else { | |
val half = powMod(x, y / 2, mod) | |
if (y % 2 == 0) half * half % mod | |
else (half * half % mod) * (x % mod) % mod | |
} | |
} | |
def main(args: Array[String]): Unit = { | |
println(powMod(2790, 2753, 3233)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment