Given an array of integers and a positive integer k
, determine the number of (i,j)
pairs where and ar[i]
+ ar[j]
is divisible by k
.
Complete the divisibleSumPairs function in the editor below.
divisibleSumPairs has the following parameter(s):
The first line contains 2 space-separated integers n, and k.
The second line contains n space-separated integers, each a value of arr[i].
STDIN Function
6 3 n = 6, k = 3
1 3 2 6 1 2 ar = [1, 3, 2, 6, 1, 2]
5
def divisibleSumPairs(n, k, ar):
answer = 0
for i in range(n-1):
for j in range(i+1,n):
if (ar[i] + ar[j]) % k == 0:
answer += 1
return answer
범위가 작아서 이중 for문으로 모든 경우를 확인했다!