题目链接:http://lightoj.com/volume_showproblem.php?problem=1213
嘛。。。sb题
发现对于循环最内层的每一项,都有n中选择,也就是一个
∑n−1i=0ai
所以答案是
knk−1∑n−1i=0ai
#include <stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
LL qpow(LL a,LL b,LL mod){
LL ans=1;
if(a==0)return 0;
while(b){
if(b&1){
ans*=a;
ans%=mod;
}
b>>=1;
a*=a;
a%=mod;
}
return ans;
}
int main(void)
{
int t,cas=0;
scanf("%d",&t);
while(t--){
LL n,k,mod;
scanf("%lld%lld%lld",&n,&k,&mod);
LL sum=0,ai;
for(int i=1;i<=n;i++){
scanf("%lld",&ai);
sum+=ai;
sum%=mod;
}
printf("Case %d: %lld\n",++cas,((qpow(n,k-1,mod)*sum)%mod*k)%mod);
}
return 0;
}

本文提供了一道来自LightOJ平台的编号为1213的问题解决方案,通过数学推导简化了问题,并使用C++实现了解决方案。核心在于计算特定数学表达式的值并进行取模运算。
2241

被折叠的 条评论
为什么被折叠?



