Fantasy of a Summation n个数,k层重复遍历相加。求它的和%mod的值;推导公式+快速幂
2017-03-31 13:30
495 查看
/** 题目:Fantasy of a Summation 链接:https://vjudge.net/contest/154246#problem/L 题意:n个数,k层重复遍历相加。求它的和%mod的值; 思路:很容易想到n个数出现在要加的和中的次数相同。 又所有数的出现次数为n^k * k: 所以每个数出现的次数为n^k * k / n; */ #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<cmath> using namespace std; typedef long long ll; const int maxn = 1004; int mod; int a[maxn]; int n, k; ll solve(ll a,ll b) { ll p = 1; while(b>0){ if(b&1) p = p*a%mod; a = a*a%mod; b >>= 1; } return p; } int main() { int T, cas=1; cin>>T; while(T--) { scanf("%d%d%d",&n,&k,&mod); for(int i = 0; i < n; i++) scanf("%d",&a[i]); ll sum = 0; for(int i = 0; i < n; i++) sum += a[i]; sum%=mod; printf("Case %d: %lld\n",cas++,solve(n,k-1)*k%mod*sum%mod); } return 0; }
相关文章推荐
- LightOJ 1213 Fantasy of a Summation(快速幂)
- Light OJ 1213 Fantasy of a Summation (快速幂+规律)
- L - Fantasy of a Summation(快速幂)
- LightOj 1220 Fantasy of a Summation(快速幂)
- LightOJ - 1213 Fantasy of a Summation 推快速幂
- LightOj 1213 - Fantasy of a Summation(推公式 快速幂)
- LightOJ - 1213 Fantasy of a Summation (快速幂)
- 【找规律 && 快速幂 && 概率论】LightOJ - 1213 Fantasy of a Summation
- LightOJ 1213 Fantasy of a Summation
- Fantasy of a Summation
- lightoj 1213 - Fantasy of a Summation 【数学计数】
- lightOJ 1213 Fantasy of a Summation
- hdu 4565 公式推导+矩阵快速幂
- 重复选择基础公式的来源推导
- Fantasy of a Summation
- Fantasy of a Summation(找规律,水)
- 目标跟踪系列十三:Exploiting the Circulant Structure of Tracking-by-detection with Kernels 公式详细的推导
- bnu 34985 Elegant String(矩阵快速幂+dp推导公式)
- LightOJ 1213 - Fantasy of a Summation (排列组合+快速幂)
- ZOJ1199Point of Intersection【公式推导】