Pairs with Divisible Sums

Sometimes you need to check pairs of elements against a simple rule, like whether their sum divides evenly by a number. The function divisible_sum_pairs receives a list ar and an integer k. Count the pairs of indices (i, j) where i < j and ar[i] + ar[j] is divisible by k with no remainder.

Примеры

Ввод
[1, 2, 3, 4, 5, 6], 5
Вывод
3
Ввод
[1, 3, 2, 6, 1, 2], 3
Вывод
5
Ввод
[1, 2, 3, 4, 5, 6], 3
Вывод
5

Нужно реализовать

def divisible_sum_pairs(ar: list[int], k: int) -> int:

Теги

arraytwo-pointersmath
PostgreSQLv16

Тук ще се появи резултатът от изпълнението на кода

Visible tests
1
Input
[1,2,3,4,5,6], 5
Expected3
2
Input
[1,3,2,6,1,2], 3
Expected5
3
Input
[1,2,3,4,5,6], 3
Expected5
4
Input
[2,2,2,2], 2
Expected6
5
Input
[1], 2
Expected0
6
Input
[1], 7
Expected0
Focus radio
Paused · SomaFM · Fluid