Skip to content

Commit

Permalink
Merge pull request #17 from AlgoLeadMe/5-mong3125
Browse files Browse the repository at this point in the history
5-mong3125
  • Loading branch information
mong3125 authored Mar 4, 2024
2 parents 25ce19e + 3524476 commit 4d7cb06
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions mong3125/μˆ˜ν•™/BOJ10986.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class BOJ10986 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());

st = new StringTokenizer(br.readLine());
int[] remainders = new int[N + 1]; // λΆ€λΆ„ 합을 M으둜 λ‚˜λˆˆ 리슀트
int[] remainders_count = new int[M]; // λ‚˜λ¨Έμ§€ 개수
for (int i = 1; i <= N; i++) {
remainders[i] = (remainders[i - 1] + Integer.parseInt(st.nextToken())) % M;
remainders_count[remainders[i]] += 1;
}

long count = 0;
for (int i = 0; i < M; i++) {
count += (long) remainders_count[i] * (remainders_count[i] - 1) / 2; // μ‘°ν•©
}

count += remainders_count[0]; // λ‚˜λ¨Έμ§€κ°€ 0μΌλ•Œ (i = j μΌλ•Œ)

System.out.println(count);
}
}

0 comments on commit 4d7cb06

Please sign in to comment.