hd acm2035

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

 

思路:后三位只跟后三位相乘有关,所以可以每乘一次都对1000取余。

 

代码:

#include <stdio.h>
#include <stdlib.h>

int main()
{
  int result,i,m,n;
  while(scanf("%d%d",&m,&n)!=EOF&&(m||n))
  {
  result=1;
    for(i=0;i<n;i++){

    result=(result*m)%1000;
    }
  printf("%d\n",result);
  }
return 0;
}

posted @ 2017-08-24 21:56  北梗  阅读(72)  评论(0编辑  收藏  举报