A bitwise pair
Practice
1.9 (15 votes)
Algorithms
Basics of greedy algorithms
C++
Greedy algorithms
Problem
66% Success 2341 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\)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
16 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
2.Dorsplen
Points:20
15 votes
Tags:
AlgorithmsApprovedEasyGreedy Algorithms
Points:20
37 votes
Tags:
AlgorithmsApprovedEasyGreedy AlgorithmsOpen
Editorial
Login to unlock the editorial