-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ10986_3.java
More file actions
34 lines (25 loc) · 807 Bytes
/
Copy pathJ10986_3.java
File metadata and controls
34 lines (25 loc) · 807 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
package TIL;
import java.util.*;
import java.io.*;
public class J10986_3 {
public static void main(String[] args) throws IOException {
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
String[] input = buffer.readLine().split(" ");
int n = Integer.parseInt(input[0]);
int m = Integer.parseInt(input[1]);
long[] mod = new long[m];
input = buffer.readLine().split(" ");
long sum = 0;
for(int i = 0; i < n; i++){
sum += Integer.parseInt(input[i]);
mod[(int)(sum%m)]++;
}
long ans = mod[0];
for(int i = 0; i < m; i++){
if(mod[i]>1){
ans += (mod[i] * (mod[i]-1))/2;
}
}
System.out.println(ans);
}
}