杭电 oj 2035 人见人爱A^B C++

Problem Description 求A^B的最后三位数表示的整数。
说明:A^B的含义是“A的B次方”

Input 输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理。
Output 对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行。

Sample Input2 3
12 6
6789 10000
0 0
Sample Output8
984
1

#include"iostream"
#include"cmath"
using namespace std;
int main()
{
 int n,m,num;
 while(cin>>n>>m&&n&&m)
 { num=1;
  for(int i=0;i<m;i++)
  num=num*n%1000;
     cout<<num<<endl;
 }
return 0;
}
发布了23 篇原创文章 · 获赞 8 · 访问量 436

猜你喜欢

转载自blog.csdn.net/qq_45697900/article/details/104744360