You are viewing a single comment's thread. Return to all 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()
Seems like cookies are disabled on this browser, please enable them to open this website
Divisible Sum Pairs
You are viewing a single comment's thread. Return to all comments →
Do not need the n in the function and using itertools to get all unique pairs: