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 C# (judge verdict: Accepted)

using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
		long m = long.Parse(input[0]);
		long n = long.Parse(input[1]);

		Console.WriteLine(DivideMod(m,n,1000000007));//WriteLineをWriteとすると、改行なしで出力。
	}

  static long DivideMod(long x, long a, long p)//戻り値はx^a(mod p)
{
  long num = 2;
  long answer = 1;
  long check = a;
  long memo = x%p;
  
  while(check > 0)
  {
    if(check % num == num / 2)
    {
      check -= num / 2;
      answer *= memo;
      answer %= p;
    }
  memo *= memo;
  memo %= p;
  num *= 2;
  }
  return answer;
}

  
}