Problem
You are given an array consisting of positive integers. Here, is defined as the bitwise AND of all elements of the array after replacing all elements of in range (both inclusive) with . Your task is to find:
Note that after calculating the value for some , the array is restored back to its original form. Therefore, calculating for each pair is independent.
You are given test cases.
Warning: Use FAST I/O Methods.
Input format
- The first line contains a single integer denoting number of test cases.
- For each test case:
- The first line contains a single integer denoting the length of the array.
- The second line contains space-separated integers denoting the integer array .
Output format
For each test case, print the required sum in a separate line.
Constraints
Consider the first test case, , . We want to evaluate . Calculations are shown below:
- : Replace with , we get , Bitwise AND of elements is 0.
- : Replace with , we get , Bitwise AND of elements is 1.
- : Replace with , we get , Bitwise AND of elements is 1.
- : Replace with , we get , Bitwise AND of elements is 3.
- : Replace with , we get , Bitwise AND of elements is 0.
- The sum is .
Consider the second test case, , . We want to evaluate . Calculations are shown below:
- : Replace with , we get , Bitwise AND of elements is 2.
- : Replace with , we get , Bitwise AND of elements is 4.
- The sum is .
Bitwise AND sumBitwise AND sum Solution(C++):-
Similar posts:-
- C-programming MCQs part-1
- C-programming MCQs part-2
- C-programming MCQs part-3
- C-programming MCQs part-4
- C-programming MCQs part-5
- C-programming MCQs part-6
- COA MCQs part-1
- COA MCQs part-2
- COA MCQs part-3
- COA MCQs part-4
- Microprocessor 8085 MCQs part-1
- Microprocessor 8085 MCQs part-2
- Microprocessor 8085 MCQs part-3
- CSS MCQs part-1
- CSS MCQs part-2
- CSS MCQs part-3
- CSS MCQs part-4
- CSS MCQs part-5
- Engineering Mathematics -II MCQs part-1
- Engineering Mathematics -II MCQs part-2
- Engineering Mathematics -II MCQs part-3
- Engineering Mathematics -II MCQs part-4
- Engineering Mathematics -II MCQs part-5
- Operating system MCQs part-1
- Operating system MCQs part-2
- Operating system MCQs part-3
- Operating system MCQs part-4
- Operating system MCQs part-5
0 Comments