lightoj 1213 - Fantasy of a Summation 【数学计数】
来源:互联网 发布:java jdbc连接池配置 编辑:程序博客网 时间:2024/06/10 19:23
题目链接:lightoj 1213 - Fantasy of a Summation
题意:求解
#include <stdio.h>int cases, caseno;int n, K, MOD;int A[1001];int main() { scanf("%d", &cases); while( cases-- ) { scanf("%d %d %d", &n, &K, &MOD); int i, i1, i2, i3, ... , iK; for( i = 0; i < n; i++ ) scanf("%d", &A[i]); 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; } ... } } } printf("Case %d: %d\n", ++caseno, res); } return 0;}
公式:
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#include <stack>#define PI acos(-1.0)#define CLR(a, b) memset(a, (b), sizeof(a))#define fi first#define se second#define ll o<<1#define rr o<<1|1using namespace std;typedef long long LL;typedef pair<int, int> pii;const int MAXN = 1e7 + 1;const int pN = 1e6;// <= 10^7const int INF = 0x3f3f3f3f;//const int MOD = 1e9 + 7;void getmax(int &a, int b) {a = max(a, b); }void getmin(int &a, int b) {a = min(a, b); }int MOD;void add(LL &x, LL y) { x += y; x %= MOD; }LL a[1010];LL Pow(LL a, int n) { LL ans = 1; while(n) { if(n & 1) ans = ans * a % MOD; a = a * a % MOD; n >>= 1; } return ans;}int main(){ int t, kcase = 1; scanf("%d", &t); while(t--) { int n, k; scanf("%d%d%d", &n, &k, &MOD); LL sum = 0; for(int i = 0; i < n; i++) { scanf("%lld", &a[i]); add(sum, a[i]); } printf("Case %d: ", kcase++); if(k == 1) { printf("%lld\n", sum); } else { LL ans = 1LL * k * Pow(n, k-1) % MOD * sum % MOD; printf("%lld\n", ans); } } return 0;}
0 0
- lightoj 1213 - Fantasy of a Summation 【数学计数】
- light oj 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 (排列组合+快速幂)
- LightOJ 1213 Fantasy of a Summation(快速幂)
- Fantasy of a Summation
- Fantasy of a Summation
- LightOj 1220 Fantasy of a Summation(快速幂)
- 【Light】[1213]Fantasy of a Summation
- lightoj1213 - Fantasy of a Summation
- LightOJ1213 Fantasy of a Summation
- light oj 1220 Fantasy of a Summation
- Light OJ 1213 Fantasy of a Summation (快速幂+规律)
- Fantasy of a Summation(找规律,水)
- ZOJ 1007 Numerical Summation of a Series (数学)
- ACM_1007_Numerical Summation of a Series
- 图论训练1A,uva4255 拓扑排序
- Hadoop学习笔记—4.初识MapReduce
- sql经典题
- \r\n
- 欢迎使用CSDN-markdown编辑器
- lightoj 1213 - Fantasy of a Summation 【数学计数】
- 自定义标题栏的问题
- 剪花布条 (HDU_2087) KMP
- 和为s的两个数字VS和为s的连续证正数序列
- LocalBroadcastManager
- 动态规划
- 采药
- Android中ListView的几种常见的优化方法
- inieditor操作conf、ini文件新思路