Skip to content

Instantly share code, notes, and snippets.

@ihainan
Created August 4, 2018 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihainan/41b13eabbb38b0b3f4a98281991d384f to your computer and use it in GitHub Desktop.
Save ihainan/41b13eabbb38b0b3f4a98281991d384f to your computer and use it in GitHub Desktop.
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