Skip to content

Instantly share code, notes, and snippets.

@mym0404
Created June 14, 2022 06:54
Show Gist options
  • Save mym0404/36d37157c420d209a4a53820bb0261a0 to your computer and use it in GitHub Desktop.
Save mym0404/36d37157c420d209a4a53820bb0261a0 to your computer and use it in GitHub Desktop.
n, m = map(int, input().split())
a = list(map(int, input().split()))
psum = [0] * (n + 1)
for i in range(n):
psum[i + 1] = (psum[i] + a[i]) % m
answer = 0
remainder_cnt = [0] * m
remainder_cnt[0] = 1
for i in range(1, n + 1):
answer += remainder_cnt[psum[i]]
remainder_cnt[psum[i]] += 1
print(answer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment