人见人爱A^B
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 2 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
求A^B的最后三位数表示的整数。
说明:A^B的含义是“A的B次方”
Input
输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1
int mul(int a,int b);
int main()
{int a,b,re;
while(scanf("%d%d",&a,&b)!=EOF&&!(a==0&&b==0));
{
printf("%d\n",mul(a%1000,b));
}
return 0;
}
int mul(int a,int b)
{ int re,mu;
if(b%2==0)
{mu=a*a%1000;
re=mul(mu,b/2);
return re%1000;
}
else if(b==1) return a;
else
{
mu=a*a%1000;
re=a*mul(mu,b/2);
return re%1000;
}
return re%1000;
}
怎么不对呀··
|