现在的位置: 首页 > 综合 > 正文

HDU 4506 小明系列故事——师兄帮帮忙

2013年10月21日 ⁄ 综合 ⁄ 共 577字 ⁄ 字号 评论关闭

快速幂,模版题

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define MOD 1000000007
#define maxn 10010
inline int Max(int a,int b){return a>b?a:b;}

#define LL long long
LL mods(LL  a,LL b,LL  n)
{
	LL ret=1;
	LL tmp=a;
	while(b)
	{
		if(b&0x1) ret=(ret*tmp)%n;
		tmp=(tmp*tmp)%n;
		b>>=1;
	}
	return ret;
}
LL a[maxn],ans[maxn];
int main()
{
	LL i,n;
	LL k,t;
	int T;scanf("%d",&T);
	while(T--){
		scanf("%I64d%I64d%I64d",&n,&t,&k);
		for(i=0;i<n;i++)scanf("%I64d",&a[i]);
		LL temp=mods(k,t,MOD);
		if(!temp)temp=1;
		for(i=0;i<n;i++)ans[(i+t)%n]=(a[i]*temp)%MOD;
		for(i=0;i<n-1;i++)
		printf("%I64d ",ans[i]);
		printf("%I64d\n",ans[i]);
	}
	return 0;
}

抱歉!评论已关闭.