A bitwise pair
Practice
1.9 (15 votes)
Algorithms
Basics of greedy algorithms
C++
Greedy algorithms
Problem
66% Success 2340 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array \(A\) of \(N\) positive integers. Find the number of pairs \((i,j)\) such that:
- \((A[i] \ | \ A[j]) - (A[i] \ \& \ A[j]) \ = \ (A[i] - A[j])\), where \(|\) is a bitwise OR operator and \(\&\) is a bitwise AND operator.
Input format
- The first line contains an integer \(T\) denoting the number of test cases.
- The first line of each test case contains an integer \(N\).
- The second line of each test case contains \(N\) space-separated integer denoting array \(A\) .
Output format
For each test case, print the number of pairs, in a new line, satisfying the equation.
Constraints
\(1 \le T \le 10 \\ 1 \le N \le 10^5 \\ 1 \le A[i] \le 10^3\)
Submissions
Please login to view your submissions
Similar Problems
Points:20
12 votes
Tags:
AlgorithmsEasyGreedy AlgorithmsString Manipulationsorting
Points:20
4 votes
Tags:
AlgorithmsBit manipulationEasyGreedy AlgorithmsHash Maps
Points:20
7 votes
Tags:
AlgorithmsEasyGreedy AlgorithmsRecruit
Editorial