E - Fantasy of a Summation
Problem Description
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.
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
Sample Input
23 1 350001 2 32 3 350001 2
Sample Output
Case 1: 6Case 2: 36
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include
题解:
仔细研究一下代码会发现只是一条公式:k*n^(k-1)*(a1+a2+...+an)
然后快速幂即可,注意不要被循环绕晕