백준 10986번: 나머지 합 #Python

ColorlessDia·2025년 7월 2일

algorithm/baekjoon

목록 보기
591/836
N, M = map(int, input().split())
A_sequence = map(int, input().split())

rest_dict = {0: 1}
prefix_sum = 0
count = 0

for A in A_sequence:
    prefix_sum += A

    R = prefix_sum % M

    count += rest_dict.get(R, 0)
    rest_dict[R] = rest_dict.get(R, 0) + 1

print(count)

0개의 댓글