dev.Log
10986 나머지합구하기 본문
import java.util.Scanner;
public class RemainSum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
long[] S = new long[N];
long[] C = new long[M];
long answer = 0;
S[0] = sc.nextInt(); //합배열
for(int i=1; i<N; i++) {
S[i] = S[i-1] + sc.nextInt();
}
for(int i=0; i<N; i++) {
int remainder = (int) (S[i] % M);
if(remainder == 0) answer ++;
C[remainder] ++;
}
for(int i=0; i<M; i++) {
if(C[i] > 1) {
answer = answer + (C[i] * (C[i]-1)/2 );
}
}
System.out.print(answer);
}
}
'알고리즘' 카테고리의 다른 글
1253 투포인터 (0) | 2022.09.08 |
---|---|
2018 연속합 (0) | 2022.09.05 |
11659 구간합 (1) | 2022.09.02 |
1546 평균구하기 (0) | 2022.09.02 |
11720 숫자의합 (0) | 2022.09.02 |
Comments