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++11 (judge verdict: Accepted)

#include <bits/stdc++.h>

using namespace std;

class Inverse {
private:
  long long mod;
	vector<long long> inv;
  
public:
  Inverse() {}
  
	Inverse(long long mod, long long n = 1000000) : mod(mod) {
    inv = vector<long long>(n, 1);
    for (int i = 2; i < n; ++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
  }
  
	long long operator()(long long a) const {
		if (a < (int)inv.size()) return inv[a];
		long long b = mod, x = 1, y = 0;
		while (b) {
			long long t = a / b;
			swap(a -= t * b, b);
			swap(x -= t * y, y);
		}
		return (x %= mod) < 0 ? x + mod : x;
	}
};

class Mint {
private:
  static long long mod;
  static Inverse inverse;
  long long val;
	
public:
	Mint() {}

	Mint(const long long& val) {
    this->val = val % mod;
    if (this->val < 0) this->val += mod;
  }

  static void setMod(const long long& m) {
    mod = m;
    inverse = Inverse(m);
  }
	
	Mint operator+=(const Mint& m) {
		val += m.val;
		if (val >= mod) val -= mod;
		return *this;
	}
  
	Mint operator-=(const Mint& m) {
		val -= m.val;
		if (val < 0) val += mod;
		return *this;
	}
  
	Mint operator*=(const Mint& m) {
		val *= m.val;
		val %= mod;
		return *this;
	}
  
	Mint operator/=(const Mint& m) {
		val *= inverse(m.val);
		val %= mod;
		return *this;
	}
	
	Mint operator+(const Mint& m) const {
		Mint res = *this;
		res += m;
		return res;
	}
	
	Mint operator-(const Mint& m) const {
		Mint res = *this;
		res -= m;
		return res;
	}
	
	Mint operator*(const Mint& m) const {
		Mint res = *this;
		res *= m;
		return res;
	}
	
	Mint operator/(const Mint& m) const {
		Mint res = *this;
		res /= m;
		return res;
	}
	
	Mint operator++() {return val += 1;}
	
	operator long long() {
		return val;
	}
};

Mint pow(const Mint& m, long long n) {
  if (n == 0) {
    return 1;
  } else if (n < 0) {
    return pow(m, -n);
  }
  Mint mm = pow(m, n / 2);
  mm *= mm;
  if (n % 2) mm *= m;
  return mm;
}

long long Mint::mod = 1000000007;
Inverse Mint::inverse(1000000007);

ostream& operator<<(ostream& os, Mint a) {
	os << (long long)a;
	return os;
}

istream& operator>>(istream& is, Mint& a) {
	long long n;
	is >> n;
	a = n;
	return is;
}

int main() {
  Mint m;
  int n;
  cin >> m >> n;
  cout << pow(m, n) << endl;
}