Skip to content

Commit dbbbd3c

Browse files
authored
Create 백준-10986-나머지합.java
1 parent 2a7d96d commit dbbbd3c

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main{
6+
7+
public static void main(String[] args) throws IOException{
8+
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
12+
StringTokenizer st = new StringTokenizer(br.readLine());
13+
14+
int N = Integer.parseInt(st.nextToken());
15+
int M = Integer.parseInt(st.nextToken());
16+
17+
long[] sumarr = new long[N];
18+
long[] count = new long[M];
19+
20+
long answer = 0;
21+
22+
st = new StringTokenizer(br.readLine());
23+
24+
sumarr[0] = Long.parseLong(st.nextToken());
25+
26+
for(int i = 1; i<N; i++){
27+
sumarr[i] = Long.parseLong(st.nextToken()) + sumarr[i-1];
28+
}
29+
30+
for(int p = 0; p<N; p++){
31+
int temp = (int)(sumarr[p]%M);
32+
33+
if(temp == 0) answer++;
34+
35+
count[temp]++;
36+
}
37+
38+
for(int m = 0; m<M; m++){
39+
40+
if(count[m]>1){
41+
answer = answer + (count[m] * (count[m] - 1) / 2);
42+
}
43+
}
44+
45+
bw.write(answer+"");
46+
bw.flush();
47+
}
48+
}

0 commit comments

Comments
 (0)