-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaekjoon_10986.java
More file actions
36 lines (25 loc) · 1.06 KB
/
baekjoon_10986.java
File metadata and controls
36 lines (25 loc) · 1.06 KB
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
import java.util.*;
import java.io.*;
public class baekjoon_10986 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
long[] sum = new long[N+1];
long[] dp = new long[M];
st = new StringTokenizer(br.readLine());
long cnt = 0;
for(int i=1;i<=N;i++) {
int num =Integer.parseInt(st.nextToken());
sum[i]= (sum[i-1] + num) % M;
if(sum[i] % M == 0) cnt++;
dp[(int) sum[i]] += 1;
}
for(int i=0;i<M;i++) {
cnt += (dp[i] * (dp[i] - 1)) / 2;
}
System.out.println(cnt);
}
}