We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f706925 commit 73c4891Copy full SHA for 73c4891
live10/test109/문제1/박희경.py
@@ -5,15 +5,21 @@
5
n, m = map(int, input().split())
6
a = list(map(int, input().split()))
7
8
-start, end = 0, 0
9
-total = a[0]
10
-cnt = 0
11
-while start <= end:
12
- if total % m == 0:
13
- cnt += 1
+remain = [0] * m # 나머지 개수
+prefix_sum = 0
+for i in range(n):
+ prefix_sum += a[i]
+ remain[prefix_sum % m] += 1
14
15
- total -= a[start]
16
- start += 1
17
- end += 1
18
- if end < n:
19
- total += a[end]
+res = remain[0]
+# 나머지가 같은 구간 2개를 뽑으면 나머지가 0이 됨
+for r in remain:
+ # 조합; rC2 = r(r-1) / 2
+ res += r * (r - 1) // 2
+
20
+print(res)
21
22
+"""
23
+5 3
24
+1 2 3 1 2
25
0 commit comments