标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 27954 Accepted Submission(s): 19117
/* * 对幂取模如对37的4次方取模 * (37*37*37*37)%m * ==(37%m*(37*37*37)%m)%m * ==(37%m*(37%m*(37*37)%m)%m)%m * ==(37%m*(37%m*(37%m*37%m)%m)%m)%m */ //求n^m%1000 s=n; for(i=1;i<m;i++) { s=s*n; s=s%1000; }
AC代码:
#include<stdio.h> #include<string.h> int main() { int n,m,i,j,s; while(scanf("%d%d",&n,&m)&&n!=0&&m!=0) { s=n; for(i=1;i<m;i++) { s=s*n; s=s%1000; } printf("%d\n",s); } return 0; }
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4674613.html