Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with three integers: n (1 ≤ n ≤ 1000), K (1 ≤ K < 231), MOD (1 ≤ MOD ≤ 35000). The next line contains n non-negative integers denoting A0, A1, A2 … An-1. Each of these integers will be fit into a 32 bit signed integer.
Output
For each case, print the case number and result of the code.
Sample Input
2
3 1 35000
1 2 3
2 3 35000
1 2
Sample Output
Case 1: 6
Case 2: 36
根据给出的代码推个公式就行了。老是有一种错觉,不会爆int……于是暴躁的搜索int替换成long long,然后就出现了long long main()(大雾)
#include<cstdio>
long long n,k,mod,a;
long long t;
long long qpow(long long a,long long b)
{
long long ret=1;
for(;b;b>>=1)
{
if(b&1)ret=ret*a%mod;
a=a*a%mod;
}
return ret;
}
int main()
{
//freopen("in.txt","r",stdin);
scanf("%lld",&t);
for(long long ca=1;ca<=t;ca++)
{
scanf("%lld%lld%lld",&n,&k,&mod);
long long sum=0;
for(long long i=1;i<=n;i++)
{
scanf("%lld",&a);
sum=(sum+a)%mod;
}
printf("Case %lld: %lld\n",ca,((sum*k%mod)*qpow(n,k-1)%mod));
}
return 0;
}
总结
推公式