题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2035
算法特工队QQ群:979618872 (伸手党绕边,欢迎有良好基础的人加入)
//
// Created by Leo Lee on 2019/4/5.
//
//递归+这个公式A^B%1000 = (A^(B/2)%1000*A^(B/2)%1000)%1000
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int getLastThree(int a,int b);
int main(){
int a,b;
while(cin>>a>>b&&(a!=0 || b!=0)){
cout<<getLastThree(a,b)<<endl;
}
return 0;
}
int getLastThree(int a,int b){
if(b<=2){
return (int)pow(a,b)%1000;
}else{
return (getLastThree(a,b/2)%1000*getLastThree(a,b-b/2)%1000)%1000;
}
}