Numbers whose bitwise OR and sum with N are equal | C ++ program to count numbers whose bitwise OR and sum with N are equal ; Function to find total 0 bit in a number ; Function to find Count of non - negative numbers less than or equal to N , whose bitwise OR and SUM with N are equal . ; count number of zero bit in N ; power of 2 to count ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; unsigned int CountZeroBit ( int n ) { unsigned int count = 0 ; while ( n ) { if ( ! ( n & 1 ) ) count ++ ; n >>= 1 ; } return count ; } int CountORandSumEqual ( int N ) { int count = CountZeroBit ( N ) ; return ( 1 << count ) ; } int main ( ) { int N = 10 ; cout << CountORandSumEqual ( N ) ; return 0 ; }