Submit | All submissions | Best solutions | Back to list |
NAJPR - Pairwise AND sum |
A bitwise AND takes two binary representations of equal length and performs the logical AND operation on each pair of corresponding bits. The result in each position is 1 if the first bit is 1 and the second bit is 1; otherwise, the result is 0. In this, we perform the multiplication of two bits; i.e., 1 × 0 = 0 and 1 × 1 = 1. For example:
0101 (decimal 5)
AND 0011 (decimal 3)
= 0001 (decimal 1)
You are given a sequence of N integer numbers A. Calculate the sum of Ai AND Aj for all the pairs (i, j) where i < j.
The AND operation is the Bitwise AND operation, defined first.
Input:
The first line of the input contains an integer T (T<=10) denoting the number of test cases. Each test case contains total defaulter number N. N≤10^5.
The second line contains N integer numbers - the sequence A. Ai <= 10^6.
Output:
For each case, print the case number and find the best place to stand in the line so that you are selected.
Sample:
Input |
Output |
2 5 1 2 3 4 5 6 1 2 3 4 5 6
|
Case 1: 9 Case 2: 21 |
Added by: | Najmuzzaman |
Date: | 2015-03-13 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ADA95 ASM64 MAWK BC C-CLANG NCSHARP CPP14-CLANG COFFEE D-CLANG D D-DMD DART ELIXIR ERL FANTOM FORTH JS-MONKEY JULIA KTLN NIM OBJC OBJC-CLANG OCT PICO PROLOG PYPY3 R RACKET RUST SCALA SCM guile SCM qobi CHICKEN SED ST SQLITE SWIFT UNLAMBDA WHITESPACE |