学过快速幂后,so easy
A^B的后三位,傻瓜式代入就好了。
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int n,m;
while(scanf("%d%d",&n,&m),n,m)
{
int res=1;
while(m){
if(m&1)
res=(res*n)%1000;
m=m>>1;
n=(n*n)%1000;
}
cout<<res<<endl;
}
return 0;
}
当然由于这题水水的,这样也是能过的哟
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int n,m;
while(scanf("%d%d",&n,&m),n,m)
{
int tt=1;
while(m--)
{
tt=tt*n%1000;
}
cout<<tt<<endl;
}
return 0;
}
考虑到当n大大的时候,时间效率还是快速幂更为优 了