思路:结果只与a的最后三位有关,故可每次对a求余,a%=1000,再通过一个for循环即可
代码:
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int a, b, c;
while (cin >> a >> b &&(a || b))//条件:存入时,且a或b都不为零时
{
c = a % 1000;
for (int i = 1; i < b; i++)
{
c = (c*a) % 1000;
}
cout << c << endl;
}
return 0;
}