题解 : 模板题, 快速幂入门.
code:
/*
adrui's submission
Language : C++
Result : Accepted
Love : ll
Favorite : Dragon Balls
Standing in the Hall of Fame
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<iostream>
#include<bitset>
#include<map>
using namespace std;
#define M(a, b) memset(a, b, sizeof(a))
#define mid ((l + r) >> 1)
#define ls rt << 1, l, mid
#define rs rt << 1|1, mid + 1, r
#define lowbit(x) (x & (-x))
#define LL long long
#define REP(n) for(int i = 1; i <= n; i++)
#define debug 0
#define mod 1000
int n, m;
int fast_multi(int a, int b) {
int ans = 0;
while (b) {
if (b & 1) ans = (ans + a) % mod;
a = (a + a) % mod;
b >>= 1;
}
return ans;
}
int fast_mod() {
int res = 1;
while (m) {
if (m & 1) res = fast_multi(res, n);
n = fast_multi(n, n);
m >>= 1;
}
return res;
}
int main() {
#if debug
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif //debug
while (~scanf("%d%d", &n, &m), n + m) {
printf("%d\n", fast_mod());
}
return 0;
}