题意:
优化题目给的代码…
思路:
对于每个A[i]都是一样的,
所以我们算出来总的A[i]出现的次数/n就可以知道每一个出现的次数
总的次数是(n^k)*k,所以每个出现(n^(k-1))*k
所以答案是Sum*(n^(k-1))*k%mod
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long LL;
const int maxn = 100005;
const int inf=(1<<28)-1;
LL quick_mod(LL a,LL b,LL mod)
{
LL res=1,tmp=a;
while(b)
{
if(b&1) res=(res*tmp)%mod;
tmp=(tmp*tmp)%mod;
b/=2;
}
return res;
}
int main()
{
int Case=0,T;
scanf("%d",&T);
while(T--)
{
int n,k,mod;
scanf("%d%d%d",&n,&k,&mod);
LL Sum=0;
for(int i=1;i<=n;++i)
{
LL x;
scanf("%lld",&x);
Sum+=x;
Sum%=mod;
}
LL Ans=(quick_mod(n,k-1,mod)*k)%mod;
Ans=(Ans*Sum)%mod;
printf("Case %d: %lld\n",++Case,Ans);
}
return 0;
}