File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ public static void main (String [] args ) throws Exception {
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+ long answer = 0 ;
15+
16+ long prefix = 0 ;
17+
18+ st = new StringTokenizer (br. readLine());
19+ for (int i = 0 ; i < N ; i++ ) {
20+ prefix = (prefix + Integer . parseInt(st. nextToken())) % M ;
21+ count[(int ) prefix]++ ;
22+ }
23+
24+ answer += count[0 ];
25+
26+ for (int i = 0 ; i < M ; i++ ) {
27+ long c = count[i];
28+ if (c >= 2 ) {
29+ answer += (c * (c - 1 )) / 2 ;
30+ }
31+ }
32+
33+ System . out. println(answer);
34+ }
35+ }
36+ ```
You can’t perform that action at this time.
0 commit comments