-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ10986.java
More file actions
42 lines (32 loc) · 1011 Bytes
/
Copy pathJ10986.java
File metadata and controls
42 lines (32 loc) · 1011 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
32
33
34
35
36
37
38
39
40
41
42
package TIL;
import java.io.*;
import java.util.*;
public class J10986 {
public static void main(String[] args) throws IOException{
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
String[] input = buffer.readLine().split(" ");
int index = Integer.parseInt(input[0]);
int key = Integer.parseInt(input[1]);
long[] array = new long[index];
long[] cnt = new long[key];
input = buffer.readLine().split(" ");
long sum = 0;
long count = 0;
long result = 0;
for(int i = 0; i < index; i++){
sum += Long.parseLong(input[i]);
array[i] = sum%key;
if(array[i] == 0){
count++;
}
cnt[(int)array[i]]++;
}
result = count;
for(int i = 0; i < key; i++){
if(cnt[i] >1){
result += (cnt[i]*(cnt[i]-1))/2;
}
}
System.out.println(result);
}
}