HDU 3923 Invoker
人见人爱A^B
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 50672 Accepted Submission(s): 33817
Problem Description
求A^B的最后三位数表示的整数。
说明:A^B的含义是“A的B次方”
Input
输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理。
Output
对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行。
Sample Input
2 312 66789 100000 0
Sample Output
89841
Author
lcy
Source
Recommend
lcy | We have carefully selected several similar problems for you: 1021 2034 1008 2033 1108
Problem Idea
【题意】
题意为:求A^B的后3位数字
【类型】
快速幂取模
【分析】
快速幂取模模板题,入门。
AC Souce Code
#include <iostream>
using namespace std;
typedef long long ll;
ll quick(ll a,ll b,ll c){
ll ans=1;
a=a%c;
while(b){
if(b&1) ans=(ans*a)%c;
b>>=1;
a=(a*a)%c;
}
return ans;
}
int main(int argc, char** argv) {
ll a,b;
while(cin>>a>>b){
if(a==0&&b==0) break;
ll ans=quick(a,b,1000);
cout<<ans<<endl;
//printf("%03lld",ans);//不足3位自动补全0
}
return 0;
}