-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_10986.java
More file actions
31 lines (24 loc) · 924 Bytes
/
BOJ_10986.java
File metadata and controls
31 lines (24 loc) · 924 Bytes
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
import java.io.*;
import java.util.*;
public class BOJ_10986 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
long result = 0;
long[] arrSum = new long[n+1];
long[] leftNum = new long[m];
st = new StringTokenizer(br.readLine());
for(int i = 1; i <= n; i++) {
arrSum[i] = arrSum[i-1] + Integer.parseInt(st.nextToken());
if(arrSum[i] % m == 0) result++;
leftNum[(int)(arrSum[i] % m)]++;
}
for(int i = 0; i < m; i++) {
long cnt = leftNum[i];
if(cnt >= 2) result += (cnt * (cnt-1) / 2);
}
System.out.println(result);
}
}