题解:根据题目给的程序,就是计算给的这个序列,进行k次到n的循环,每个数需要加的次数是k*n^(k-1),所以快速幂取模,算计一下就可以了。

#include <bits/stdc++.h>

using  namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f3f;
long long pow_mod(ll a, ll k, ll mod)
{
ll ans = 1;
while(k)
{
if(k%2)
ans *= a;
ans %= mod;
a = a * a;
a %= mod;
k /=2;
}
return ans;
}
int main()
{
int T;
ll n,k,mod,x,sum;
while(~scanf("%d",&T))
{
int cas = 1;
while(T--)
{
sum = 0;
scanf("%lld%lld%lld",&n,&k,&mod);
for(ll i = 0; i < n; i ++)
{
scanf("%lld",&x);
sum += (x * (k * pow_mod(n,k-1,mod)%mod)%mod);
sum %= mod;
}
printf("Case %d: %lld\n",cas++, sum);
}
}
return 0;
}

Problem:

If you think codes, eat codes then sometimes you may get stressed. In your dreams you may see huge codes, as I have seen once. Here is the code I saw in my dream.

#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;
}

Actually the code was about: 'You are given three integers n, K, MOD and n integers: A0, A1, A2 ... An-1, you have to write K nested loops and calculate the summation of all Ai where i is the value of any nested loop variable.'

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with three integers: n (1 ≤ n ≤ 1000), K (1 ≤ K < 231), MOD (1 ≤ MOD ≤ 35000). The next line contains n non-negative integers denoting A0, A1, A2 ... An-1. Each of these integers will be fit into a 32 bit signed integer.

Output

For each case, print the case number and result of the code.

Sample Input

2

3 1 35000

1 2 3

2 3 35000

1 2

Sample Output

Case 1: 6

Case 2: 36

最新文章

  1. 20145234黄斐《信息安全系统设计基础》GDB调试汇编堆栈过程分析
  2. 数独Sudoku
  3. UVa 400
  4. P1023 奶牛的锻炼
  5. parent children
  6. SQL Server 自学笔记
  7. Hdu 3410 【单调队列】.cpp
  8. 在Web.Config文件中使用configSource,避免动态修改web.config导致asp.net重启(另添加一个Config文件用于管理用户数据)
  9. JAVA CAS原理深度分析(转)
  10. shell 中的特殊符号的含义
  11. 【中国人大:天地人大BBS站】迟到的求职感悟
  12. Eclipse 启动报错 An internal error occurred during: &quot;Initializing Java Tooling&quot;
  13. 解决macOS git clone Azure DevOps提示身份认证失败问题
  14. sed 多行处理详细总结
  15. ID3、C4.5和CART决策树对比
  16. linux运维升级路线
  17. spring mvc 图片上传,图片压缩、跨域解决、 按天生成文件夹 ,删除,限制为图片代码等相关配置
  18. e645. 处理键盘事件
  19. Java设计模式(8)——结构型模式之组合模式(Composite)
  20. MacOs桌面自动被打乱的原因

热门文章

  1. ubutnu18.04LTS 配置网卡新特性
  2. C 中 char、signed char 和 unsigned char 的区别
  3. Myeclipse启动后tomcat空指针异常
  4. 搭建vue.js 的npm脚手架
  5. VMwarevSphere Client 链接 vCenter Server中的主机,开启虚拟机提示:在主机当前连接状况下不允许执行该操作
  6. mysql 知识整理
  7. 第十章、typing模块
  8. 经典i++和++i问题(附带运算符优先级问题)
  9. 无聊开始玩路由器,入门Tomato固件
  10. mysql数据库:数据类型、存储引擎、约束、