2 312 66789 100000 0Sample Output89841思路:求最后三位整数,即A的B次方对1000取余。代码一:用快速幂。#include<stdio.h>typedef long long LL;LL Quick_MI(LL n,LL m,LL c){ LL s=1; while(m) { n=n%c; if(m&1) { s=(s*n)%c; } n=(n*n)%c; m=m/2; } return s;}int main(){ long long n,m,k; while(~scanf("%lld%lld",&n,&m)&&(n||m)) { k=Quick_MI(n,m,1000); PRintf("%-lld/n",k); } return 0;}代码二:循环,同余定理#include<stdio.h>int main(){ int n,m,k,i; long long s; while(scanf("%d%d",&n,&m),n!=0||m!=0) { s=1; for(i=1;i<=m;i++) { s=s*n; s=s%1000; } printf("%lld/n",s); } return 0;}
新闻热点
疑难解答