File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ ```
2+ import java.io.*;
3+ import java.util.*;
4+
5+ public class Main {
6+ public static void main(String[] args) throws IOException {
7+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+ StringTokenizer st = new StringTokenizer(br.readLine());
9+
10+ int N = Integer.parseInt(st.nextToken());
11+ int M = Integer.parseInt(st.nextToken());
12+
13+ long[] count = new long[M];
14+ count[0] = 1;
15+
16+ long prefixSum = 0;
17+ st = new StringTokenizer(br.readLine());
18+
19+ for (int i = 0; i < N; i++) {
20+ prefixSum += Long.parseLong(st.nextToken());
21+ int mod = (int) (prefixSum % M);
22+ count[mod]++;
23+ }
24+
25+ long answer = 0;
26+ for (int i = 0; i < M; i++) {
27+ answer += count[i] * (count[i] - 1) / 2;
28+ }
29+
30+ System.out.println(answer);
31+ }
32+ }
33+
34+ ```
You can’t perform that action at this time.
0 commit comments