Given two numbers A, B. The task is to find the numbers of special pairs of A, B. A special pair of two numbers A, B is a pair of numbers X, Y which satisfies the both of the given conditions – A = X | Y, B = X & Y.
Input: A = 3, B = 0 Output: 2 (0, 3), (1, 2) will satisfy the conditions Input: A = 5, B = 7 Output: 0
Approach: The key observation here is that if we want the OR of two numbers, X, Y to be equal to A. Then both X, Y has to be less than or equal to A. If anyone is greater A then there OR won’t be equal to A. This will give us the limits where our loop will terminate, rest we will try and check if two pairs meet the given condition, then we will increment the counter.
Below is the required implementation:
- Count the number of special permutations
- Find Largest Special Prime which is less than or equal to a given number
- Count ordered pairs of positive numbers such that their sum is S and XOR is K
- Find Unique pair in an array with pairs of numbers
- Number of pairs with Bitwise OR as Odd number
- Count number of pairs (i, j) such that arr[i] * arr[j] > arr[i] + arr[j]
- Number of pairs whose sum is a power of 2
- Number of pairs with Pandigital Concatenation
- Count pairs with Bitwise AND as ODD number
- Count pairs with Bitwise XOR as ODD number
- Count pairs with Bitwise OR as Even number
- Number of prime pairs in an array
- Find number of pairs in an array such that their XOR is 0
- Count pairs with Bitwise XOR as EVEN number
- Count pairs with Bitwise-AND as even number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.