LightOJ 1213 Fantasy of a Summation(快速幂)
来源:互联网 发布:qq群做淘宝客赚钱吗 编辑:程序博客网 时间:2024/05/16 19:40
题目链接:
LightOJ 1213 Fantasy of a Summation
题意:
给定n,k,m求解:
int res = 0;for( i1 = 0; i1 < n; i1++ ) { for( i2 = 0; i2 < n; i2++ ) { for( i3 = 0; i3 < n; i3++ ) { ... for( iK = 0; iK < n; iK++ ) { res = ( res + A[i1] + A[i2] + ... + A[iK] ) % MOD; } ... } }}
分析:
其实就是k层循环,每层遍历n个数字,把遍历到的数字相加和取模。模拟一下可以得到:ans = sum * n^(k -1) * k
。sum是n个数字之和。然后就是快速幂计算下就好了。
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <climits>#include <cmath>#include <ctime>#include <cassert>#include <set>#define IOS ios_base::sync_with_stdio(0); cin.tie(0);using namespace std;typedef long long ll;const int MAX_N = 1010;int T, n, total, cases = 0, K;ll sum, mod, data[MAX_N];ll quick_pow(ll a, ll b){ ll res = 1, tmp = a; while(b){ if(b & 1) res = res * tmp % mod; tmp = tmp * tmp % mod; b >>= 1; } return res;}int main(){ scanf("%d", &T); while(T--){ sum = 0; scanf("%d%d%lld", &n, &K, &mod); for(int i = 0; i < n; i++){ scanf("%lld", &data[i]); sum += data[i]; sum %= mod; } ll ans = quick_pow(n, K - 1) * K % mod * sum % mod; printf("Case %d: %lld\n", ++cases, ans); } return 0;}
0 0
- LightOJ 1213 - Fantasy of a Summation (排列组合+快速幂)
- LightOJ 1213 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 【数学计数】
- Fantasy of a Summation
- Fantasy of a Summation
- Light OJ 1213 Fantasy of a Summation (快速幂+规律)
- 【Light】[1213]Fantasy of a Summation
- lightoj1213 - Fantasy of a Summation
- LightOJ1213 Fantasy of a Summation
- light oj 1213 - Fantasy of a Summation (数学计数)
- light oj 1220 Fantasy of a Summation
- Fantasy of a Summation(找规律,水)
- ACM_1007_Numerical Summation of a Series
- Numerical Summation of a Series
- Android项目使用Ant打包,自动生成build.xml
- Boost string_algo
- JavaScript的常用内置类
- CodeForces 3D Least Cost Bracket Sequence (贪心+优先队列)
- 第4章第1节练习题1 二叉树的基本操作(递归实现)
- LightOJ 1213 Fantasy of a Summation(快速幂)
- 第十四周项目一(3) 阅读程序,解释程序运行得到的结果
- Digit(湘潭大学比赛)
- ACM--木头序列--贪心+递减子序列--HDOJ 1051--Wooden Sticks
- centos6.5 下安装nmap,sqlmap
- CollapsingToolbarLayout使用的一些注意点
- Android中SQLite应用详解
- 计算机视觉-相机参数标定
- ubuntu安装和配置SVN