A^B对1000取余即可
#include <iostream> #include <string.h> #include <algorithm> #include <stdio.h> #include <math.h> #include <map> #include <string> #include <set> #include <stack> #include<queue> using namespace std; //#define forseach(i,j,n) for(int i=j;i<n;i++) #define debug freopen("in.txt","r",stdin),freopen("out.txt","w",stdout); #define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); //#define PI acos(-1) typedef long long ll; const int maxn = 1e5 + 10; ll mypow(ll &x,ll &y,int &mod) { ll ans=1; while(y) { if(y&1) ans=(x*ans)%mod; x=(x*x)%mod; y>>=1; } return ans; } int main() { //debug; ios; ll x,y; int mod=1000; while(cin>>x>>y) { if(x==0||y==0) break; cout<<mypow(x,y,mod)<<'\n'; } return 0; }