-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloj1134.cpp
83 lines (78 loc) · 1.96 KB
/
loj1134.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
80
81
82
83
//tempp//{ Template
using namespace std;
//{ C-headers
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <cctype>
#include <cassert>
#include <ctime>
//}
//{ C++-headers
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
//}
//{ Loops
#define forab(i,a,b) for (__typeof(b) i = (a); i <= (b); ++i)
#define rep(i,n) forab (i, 0, (n) - 1)
#define For(i,n) forab (i, 1, n)
#define rofba(i,a,b) for (__typeof(b) i = (b); i >= (a); --i)
#define per(i,n) rofba (i, 0, (n) - 1)
#define rof(i,n) rofba (i, 1, n)
#define forstl(i,s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
//}
//{ Floating-points
#define EPS DBL_EPSILON
#define abs(x) (((x) < 0) ? - (x) : (x))
#define zero(x) (abs (x) < EPS)
#define equal(a,b) (zero ((a) - (b)))
#define PI 2 * acos (0.0)
//}
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
#define memo(a,v) memset(a,v,sizeof(a))
#define all(a) a.begin(),a.end()
#define INF 1<<29
#define ll long long
#define db double
#define pii pair<int ,int >
#define NL puts("")
#define G getchar()
//}
int arr[100000+10],dp[100000+10],countt[100000+10];
long long int solve(int n){
if(n<=1) return 0;
return n-1+solve(n-1);
}
int main () {
int t, cs,n,m,i,j;
long long cnt;
scanf("%d",&t);
for(cs=1;cs<=t;cs++) {
scanf("%d %d",&n,&m);
for(i=0;i<=m;i++) countt[i]=0;
cnt=0;
for(i=0;i<n;i++) {
scanf("%d",&arr[i]);
if(i==0) dp[i]=arr[i]%m;
else dp[i] = (dp[i-1]%m+arr[i]%m)%m;
countt[dp[i]]++;
}
for(i=0;i<m;i++) cnt+=solve(countt[i]);
cnt+=countt[0];
printf("Case %d: %lld\n",cs,cnt);
}
return 0;
}