Fantasy of a Summation LightOJ

题意:

首先 只看第一层循环的A[0],是不是用了nk-1次  A[1]也是用了nk-1次······ 所以 第一层的sum(A[i]的和) 一共用了nk-1 所以第一层为sum * nk-1

因为又k层循环 所以全部为sum * nk-1 * k

最后不要忘了 % MOD

代码如下:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn = 10010, INF = 0x7fffffff;
typedef long long LL;
LL MOD, n, k;
LL init(LL a, LL b)
{
    LL res = 1;
    while(b)
    {
        if(b & 1 ) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

int main()
{
    int T;
    cin>> T;
    int kase = 0;
    while(T--)
    {
        cin>> n >> k >> MOD;
        LL sum = 0;
        for(int i=0; i<n; i++){
            LL temp;
            cin>> temp;
            sum = (sum + temp) % MOD; 
        }
        printf("Case %d: %lld
",++kase,sum*init(n,k-1)  * k%MOD);

    }    
    
    
    return 0;
}
自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
原文地址:https://www.cnblogs.com/WTSRUVF/p/9190280.html