• + 0 comments

    Do not need the n in the function and using itertools to get all unique pairs:

    import os
    from itertools import combinations
    
    def divisibleSumPairs(n, k, ar):
        valid_pair = 0
        all_pairs = combinations(ar, 2)
        for pair in all_pairs:
            pair_sum = sum(pair)
            if pair_sum % k == 0:
                valid_pair += 1
        return valid_pair
    
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
        
        first_multiple_input = input().rstrip().split()
        n = int(first_multiple_input[0])
        k = int(first_multiple_input[1])
        ar = list(map(int, input().rstrip().split()))
        result = divisibleSumPairs(n, k, ar)
    
        fptr.write(str(result) + '\n')
        fptr.close()