NTL_1_B | Power
Table of contents
# Problem
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_B
Given X and N, report the power N of X.
# Time complexity
# Solution
#define M 1000000007
Int X, Y;
Int faster_pow(Int x, Int y) {
if (y == 0) return 1;
Int res = faster_pow((x * x) % M, y / 2);
if (y % 2 == 1) {
res = (res * x) % M;
}
return res;
}
void input() {
cin >> X >> Y;
}
void solve() {
cout << faster_pow(X, Y) << endl;
}
int main() {
input();
solve();
return 0;
}
Shun
Remote freelancer. A web and mobile application enginner.
Traveling around the world based on East Asia.
I'm looking forward to your job offers from all over the world!