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\)

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
42 votes
Tags:
AlgorithmsApprovedEasyGreedy AlgorithmsMathOpenSorting
Points:20
34 votes
Tags:
AlgorithmsApprovedEasyGreedy AlgorithmsOpen
Points:20
7 votes
Tags:
AlgorithmsGreedy AlgorithmsBasics of Greedy Algorithms