Medium Math > Basic Math

You are given an array of N elements, you need to make some pairs using all the elements of the array where each pair’s sum is divisible by a value K. Print the pairs in lexicographically smallest one first. Lets say you have two pair (x1, y1) and (x2, y2) , (x1, y1) will come before (x2, y2) if x1 < x2 or ( x1==x2 && y1 <= y2 ) And for each pair (x, y), x = min(x, y) and y = max(x, y) For example you have an array like this: [ 9, 1, 18, 2] and given value K = 10 You should print 1 9 2 18 Input: ------ Input starts with an integer T (≤ 3), denoting the number of test cases. The next line contains two integers N (1 ≤ N ≤ 10<sup>5</sup>), K (1 ≤ K ≤ 10<sup>9</sup>). The next line contains N space separated integers forming the array. There integers range in [0, 10<sup>9</sup>]. Output: ------- For each case, print the case number first. If it is possible to make some pairs using all the elements of the array where each pair’s sum is divisible by a value K then print all the pairs from the next line lexicographic-ally sorted way otherwise print "Not Possible" without quote. See the output section for better understanding Sample Input ------------ 1 4 10 9 1 18 2 Sample Output ------------- Case 1: 1 9 2 18

Ahmad Faiyaz