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
Συνδεθείτε για να δείτε το ιστορικό υποβολών
ΣύνδεσηΣυνδεθείτε για να χρησιμοποιήσετε τον AI Mentor
ΣύνδεσηVisible tests
1
Input
[1,2,3,4,5,6], 5Expected
32
Input
[1,3,2,6,1,2], 3Expected
53
Input
[1,2,3,4,5,6], 3Expected
54
Input
[2,2,2,2], 2Expected
65
Input
[1], 2Expected
06
Input
[1], 7Expected
0Focus radio
Paused · SomaFM · Fluid