-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1213 - Fantasy of a Summation.cpp
79 lines (73 loc) · 1.72 KB
/
1213 - Fantasy of a Summation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Author: Ashraful Islam Rafi
* University: Leading University,Sylhet
* url: http://www.lightoj.com/volume_showproblem.php?problem=1213
* problem id: 1213 - Fantasy of a Summation
* complexity: 2nd level(Number theory)
* site: Lightoj.com
**/
#include"map"
#include"set"
#include"queue"
#include"cmath"
#include"stack"
#include"ctype.h"
#include"cstdio"
#include"vector"
#include"cstdio"
#include"cstring"
#include"cstdlib"
#include"string.h"
#include"iostream"
#include"algorithm"
using namespace std;
#define cs "Case "<<++casee<<": "
#define csE "Case "<<++casee<<":\n"
#define Inf 1000000000
#define N 5000010
#define MST(a, tf) memset(a, tf, sizeof (a))
unsigned long long power(unsigned long long x,unsigned long long y,unsigned long long md)
{
if(y==0) return 1;
if(y%2==1) return (x* power(x,y-1,md))%md; ///return ((x%md) * (power(x,y-1,md)%md))%md;
else
{
unsigned long long val=power(x,y/2,md);
return (val* val ) % md; ///return ((val%md) * (val %md))%md;
}
/*if(y==0) return 1;
if(y%2==1) return (x* power(x,y-1,md))%md;
else
{
//unsigned long long modulas= (k * power(n,k-1,m))%m;
unsigned long long moddz= power(x,y/2,md)%md;
return (moddz * moddz) %md;
}
*/
}
int main()
{
int t;cin>>t;int casee=0;
while(t--)
{
unsigned long long n,k,m,valu,result=0;
cin>>n>>k>>m;
for(unsigned long long i=0;i<n;i++)
{
cin>>valu;
result = (result+(valu * (k * power(n,k-1,m) %m) %m ))%m;
//result = (result+(valu * modulas) %m )%m;
}
cout<<cs<<result<<endl;
}
}
///--test case---///
/**
2
3 1 35000
1 2 3
2 3 35000
1 2
Case 1: 6
Case 2: 36
*/