LightOJ1213 Fantasy of a Summation
label
Foreword
- My blog csdn and garden are synchronized, Welcome danzh- blog Park ~
Concise meaning of the questions
- Given n, k, mod, and the size n of the array a [], requirements:
Thinking
- And the stripper can quickly find regular. Apart like this:
Precautions
- no
to sum up
- no
AC Code
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = 1e5 + 10;
int mod;
int ksm(int a, int b)
{
int ans = 1, base = a;
while (b)
{
if (b & 1)
ans = 1ll * ans * base % mod;
b >>= 1;
base = 1ll * base * base % mod;
}
return ans;
}
void solve()
{
int t;
scanf("%d", &t);
for (int i = 1; i <= t; i++)
{
int n, k;
long long sum = 0;
scanf("%d%d%d", &n, &k, &mod);
for (int i = 1; i <= n; i++)
{
int t;
scanf("%d", &t);
sum += t;
sum %= mod;
}
printf("Case %d: %d\n", i, sum * k % mod * ksm(n, k - 1) % mod);
}
}
int main()
{
freopen("Testin.txt", "r", stdin);
solve();
return 0;
}