2 3 2 5 1 2 3 3 0 5 1 2 3
50 75 25 1 2 3#include<stdio.h> #define mod 1000000007 int main() { int n,m,k,i,t; __int64 aa[60],ans[100005],sum; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&k); for(i=1;i<=n;i++) { scanf("%I64d",&ans[i]);ans[i]%=mod; } int tk=m,ti=0,a[60]; while(tk) { a[++ti]=tk%2; tk/=2; } aa[1]=k%mod; for(i=2; i<=ti;i++) aa[i]=(aa[i-1]*aa[i-1])%mod; sum=1; for(i=1; i<=ti; i++) if(a[i]) sum=(sum*aa[i])%mod; tk=m%n; if(tk)printf("%I64d",(ans[n-tk+1]*sum)%mod),ti=n-tk+1; else printf("%I64d",(ans[1]*sum)%mod),ti=1; if(ti==1) for(i=2;i<=n;i++) printf(" %I64d",(ans[i]*sum)%mod); else { i=ti-1; for(ti++; ti<=n; ti++) printf(" %I64d",(ans[ti]*sum)%mod); for(ti=1;ti<=i; ti++) printf(" %I64d",(ans[ti]*sum)%mod); } printf("\n"); } return 0; }
hdu4506小明系列故事——师兄帮帮忙 (用二进制,大数快速取余),布布扣,bubuko.com
hdu4506小明系列故事——师兄帮帮忙 (用二进制,大数快速取余)
原文:http://blog.csdn.net/u010372095/article/details/31749795