Given a number N, the task is to find the count of X such that N XOR X == N OR X, where 0<=X<=N
Input: N = 5
For N = 5,
5 XOR 2 == 5 OR 2
5 XOR 0 == 5 OR 0
Thus, count is 2.
Input: N = 7
For N = 7,
7 XOR 0 == 7 OR 0
Thus, count is 1.
Approach: The idea is to convert given number to binary and then count the unset bits in it. 2^count gives us the number of X such that N XOR X == N OR X.
Below is the implementation of the above approach:
- Count numbers whose difference with N is equal to XOR with N
- Count numbers whose sum with x is equal to XOR with x
- Count smaller numbers whose XOR with n produces greater value
- Find an N x N grid whose xor of every row and column is equal
- Count of numbers whose sum of increasing powers of digits is equal to the number itself
- Count of N digit Numbers whose sum of every K consecutive digits is equal
- Count of N digit Numbers whose sum of every K consecutive digits is equal | Set 2
- Count smaller values whose XOR with x is greater than x
- Count all pairs of adjacent nodes whose XOR is an odd number
- Count of binary strings of length N having equal count of 0's and 1's and count of 1's ≥ count of 0's in each prefix substring
- XOR of two numbers after making length of their binary representations equal
- Equal Sum and XOR of three Numbers
- Count minimum bits to flip such that XOR of A and B equal to C
- Count of elements which are equal to the XOR of the next two elements
- Find a number X such that (X XOR A) is minimum and the count of set bits in X and B are equal
- Count subarrays with sum equal to its XOR value
- Count ways to generate pairs having Bitwise XOR and Bitwise AND equal to X and Y respectively
- Count even length subarrays having bitwise XOR equal to 0
- Count numbers < = N whose difference with the count of primes upto them is > = K
- Find XOR of two number without using XOR operator
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.