You are given an array of integers. Find the XOR of all the pairwise sums formed by the elements of the array.Input FormatThe first line of input contains T - the number of test cases. It is followed by 2T lines, the first line contains N - the size of the array. The second line contains the elements of the array.Output FormatFor each test case, print the XOR product of all the pairwise sums of the elements from the array, separated by a newline.Constraints10 points1 <= T <= 1001 <= N <= 10000 <= A[i] <= 10540 points1 <= T <= 1001 <= N <= 1050 <= A[i] <= 105ExampleInput254 10 54 11 8615 35 25 10 15 12Output118120ExplanationTest-Case 1All the pairwise sums formed with 4 are (4 + 4), (4 + 10), (4 + 54), (4 + 11), (4 + 8) = 8, 14, 58, 15, 12All the pairwise sums formed with 10 are (10 + 4), (10 + 10), (10 + 54), (10 + 11), (10 + 8) = 14, 20, 64, 21, 18All the pairwise sums formed with 54 are (54 + 4), (54 + 10), (54 + 54), (54 + 11), (54 + 8) = 58, 64, 108, 65, 62All the pairwise sums formed with 11 are (11 + 4), (11 + 10), (11 + 54), (11 + 11), (11 + 8) = 15, 21, 65, 22, 19All the pairwise sums formed with 8 are (8 + 4), (8 + 10), (8 + 54), (8 + 11), (8 + 8) = 12, 18, 62, 19, 16XOR of all the above sums = (8 ^ 14 ^ 58 ^ 15 ^ 12) ^ (14 ^ 20 ^ 64 ^ 21 ^ 18) ^ (58 ^ 64 ^ 108 ^ 65 ^ 62) ^ (15 ^ 21 ^ 65 ^ 22 ^ 19) ^ (12 ^ 18 ^ 62 ^ 19 ^ 16) = 118
Question
You are given an array of integers. Find the XOR of all the pairwise sums formed by the elements of the array.Input FormatThe first line of input contains T - the number of test cases. It is followed by 2T lines, the first line contains N - the size of the array. The second line contains the elements of the array.Output FormatFor each test case, print the XOR product of all the pairwise sums of the elements from the array, separated by a newline.Constraints10 points1 <= T <= 1001 <= N <= 10000 <= A[i] <= 10540 points1 <= T <= 1001 <= N <= 1050 <= A[i] <= 105ExampleInput254 10 54 11 8615 35 25 10 15 12Output118120ExplanationTest-Case 1All the pairwise sums formed with 4 are (4 + 4), (4 + 10), (4 + 54), (4 + 11), (4 + 8) = 8, 14, 58, 15, 12All the pairwise sums formed with 10 are (10 + 4), (10 + 10), (10 + 54), (10 + 11), (10 + 8) = 14, 20, 64, 21, 18All the pairwise sums formed with 54 are (54 + 4), (54 + 10), (54 + 54), (54 + 11), (54 + 8) = 58, 64, 108, 65, 62All the pairwise sums formed with 11 are (11 + 4), (11 + 10), (11 + 54), (11 + 11), (11 + 8) = 15, 21, 65, 22, 19All the pairwise sums formed with 8 are (8 + 4), (8 + 10), (8 + 54), (8 + 11), (8 + 8) = 12, 18, 62, 19, 16XOR of all the above sums = (8 ^ 14 ^ 58 ^ 15 ^ 12) ^ (14 ^ 20 ^ 64 ^ 21 ^ 18) ^ (58 ^ 64 ^ 108 ^ 65 ^ 62) ^ (15 ^ 21 ^ 65 ^ 22 ^ 19) ^ (12 ^ 18 ^ 62 ^ 19 ^ 16) = 118
Solution
This problem is asking you to calculate the XOR of all the pairwise sums of an array of integers.
Here's a step-by-step guide on how to solve this problem:
- Read the number of test cases, T.
- For each test case, read the size of
Similar Questions
Given an array of integers of size N, print the sum of sum of all subarrays.Input FormatFirst line of input contains T - number of test cases. Its followed by 2T lines, the first line contains N - size of the array and second line contains the elements of the array.Output FormatFor each test case, print the sum of sum of all subarrays, separated by newline.Constraints10 points1 <= T <= 1001 <= N <= 10220 points1 <= T <= 1001 <= N <= 10370 points1 <= T <= 10001 <= N <= 104General Constraints-106 <= arr[i] <= 106ExampleInput333 4 521 231 -3 4Output4063ExplanationTest Case 1:[3] + [3,4] + [3,4,5] + [4] + [4,5] + [5] = 40Test Case 2:[1] + [1,2] + [2] = 6Test Case 3:[1] + [1,-3] + [1,-3,4] + [-3] + [-3,4] + [4] = 3
Sum of 2 NumbersGiven an array, check if there exist 2 elements of the array such that their sum is equal to the sum of the remaining elements of the array.Input FormatThe first line of input contains T - the number of test cases. It is followed by 2T lines, the first line contains N - the size of the array. The second line contains N integers - elements of the array.Output FormatFor each test case, print "Yes" if such elements exist, and "No" otherwise, separated by a new line.Constraints30 points1 <= T <= 1001 <= N <= 1000-106 <= A[i] <= 10670 points1 <= T <= 5001 <= N <= 10000-106 <= A[i] <= 106ExampleInput25-3 5 8 2 -465 -10 8 4 2 -3OutputYesNoExplanationExample 1:Possible values: 8 + (-4) = (-3) + 5 + 2.Example 2:No 2 elements exist whose sum is equal to the sum of the remaining array elements.
You are given an array of integers. For each element in the array, find the number of smaller elements on the right side and print the total count.Input FormatThe first line of input contains T - the number of test cases. It's followed by 2T lines, the first line contains N - the size of the array. The second line contains the elements of the array.Output FormatFor each test case, print the sum of count of smaller elements on right side of each element in the array, separated by new line.Constraints30 points1 <= N <= 10370 points1 <= N <= 105General Constraints1 <= T <= 100-104 <= A[i] <= 104ExampleInput254 10 54 11 8615 35 25 10 15 12Output410ExplanationTest Case 1Smaller Elements on right side of 4 : 0Smaller Elements on right side of 10 : 1Smaller Elements on right side of 54 : 2Smaller Elements on right side of 11 : 1Smaller Elements on right side of 8 : 0Total Count = 0 + 1 + 2 + 1 + 0 = 4Test Case 2Smaller Elements on right side of 15 : 2Smaller Elements on right side of 35 : 4Smaller Elements on right side of 25 : 3Smaller Elements on right side of 10 : 0Smaller Elements on right side of 15 : 1Smaller Elements on right side of 12 : 0Total Count = 2 + 4 + 3 + 0 + 1 + 0 = 10
Shubham and XorYou are given an array of n integer numbers 𝑎1, 𝑎2, .. ,𝑎𝑛. Calculate the number of pair of indices (𝑖,𝑗) such that 1≤𝑖 < 𝑗≤𝑛 and 𝑎𝑖 xor 𝑎𝑗=0Constraints:Input format- First line: n denoting the number of array elements- Second line: n space separated integers 𝑎1, 𝑎2, .. ,𝑎𝑛.Output formatOutput the required number of pairs.Example:Sample Input :51 3 1 4 3Sample Output :2Explanation:The 2 pair of indices are (1,3) and (2,5) .
Given an array of unique integer elements, print all the subsets of the given array in lexicographical order.Input FormatThe first line of input contains T - the number of test cases. It's followed by 2T lines, the first line contains N - the size of the array and the second line contains the elements of the array.Output FormatFor each test case, print the subsets of the given array in lexicographical order, separated by new line. Print an extra newline between output of different test cases.Constraints1 <= T <= 1001 <= N <= 100 <= A[i] <= 100ExampleInput335 15 3 257 96 43 15 8 23 Output3 3 5 3 5 15 3 15 5 5 15 15 57 57 96 96 3 3 8 3 8 15 3 8 15 23 3 8 23 3 15 3 15 23 3 23 8 8 15 8 15 23 8 23 15 15 23 23
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.