Skip to content

Commit b7e106e

Browse files
authored
Merge pull request #1467 from AlgorithmWithGod/Seol-JY
[20251121] BOJ / G3 / 나머지 합 / 설진영
2 parents a95dcb9 + 2c76b66 commit b7e106e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
```

0 commit comments

Comments
 (0)