Problem:
Power

For given integers m and n, compute mn (mod 1,000,000,007). Here, A (mod M) is the remainder when A is divided by M.

Input

m n

Two integers m and n are given in a line.

Output

Print mn (mod 1,000,000,007) in a line.

Constraints

1 ≤ m ≤ 100

1 ≤ n ≤ 109

Sample Input 1

2 3

Sample Output 1

8

Sample Input 2

5 8

Sample Output 2

390625

Solution in Scala (judge verdict: Accepted)

import scala.io.StdIn.readLine

object Main {

  def times(m:Long, n:Long, z:Long) =  ( (m%z) * (n%z) ) % z

  def pow(x:Long, y:Long, z:Long):Long = {
    def scan(m:Long, n:Long, odd:Long):Long =
      if(n==0) 1
      else if(n==1) times(m,odd,z)
      else scan(times(m,m,z), n/2, (if(n%2==1) times(odd, m, z) else odd))
    scan(x, y, 1)
  }

  def main(args: Array[String]) = {
    val n = readLine().split(" ").map(_.toLong)
    println(pow(n(0),n(1),1000000007))
  }
}