• + 0 comments

    Python

    def divisibleSumPairs(n, k, ar):
        total_pairs = 0
        remainder_count = [0] * k
        
        for num in ar:
            remainder = num % k
            complement = (k - remainder) % k
            total_pairs += remainder_count[complement]
            remainder_count[remainder] += 1
        
        return total_pairs
    

    Time complexity: O(n)