杭电2035题
#include <iostream>
using namespace std;
int mul(int a,int b);
int main()
{
int a,b;
int result;
while(cin>>a>>b)
{
if(a==0 && b==0)
return 0;
cout<<mul(a%1000,b)<<endl;
}
return 0;
}
//分不同的情况判断b的奇偶性
int mul(int a,int b)
{
int result;
int multiply;
if(b %2==0)
{
multiply = a*a%1000;
result = mul(multiply,b/2);
return result%1000;
}
else if(b==1)
{
//注:此处返回的是a
return a;
}
else
{
multiply = a*a%1000;
result = a*mul(multiply,b/2);
return result%1000;
}
return result %1000;
}