一、题目描述
样例输入:
2
3 1 35000
1 2 3
2 3 35000
1 2
二、算法分析说明与代码编写指导
已知:
三、AC 代码(8 ms)
#include<cstdio>
#pragma warning(disable:4996)
template<class _Ty> inline _Ty PowerMod(_Ty radix, _Ty exp, const _Ty& mod) {
_Ty ans = 1; radix %= mod;
while (exp) {
if (exp & 1)ans = (ans * radix) % mod;
exp >>= 1, radix = (radix * radix) % mod;
}
return ans % mod;
}
unsigned t; unsigned long long k, n, s, m, a;
int main() {
scanf("%u", &t);
for (unsigned i = 1; i <= t; ++i) {
scanf("%llu%llu%llu", &n, &k, &m); s = 0;
for (unsigned j = 0; j < n; ++j) { scanf("%llu", &a); s += a; }
printf("Case %u: %llu\n", i, ((k % m) * (s % m) % m) * PowerMod(n, k - 1, m) % m);
}
}