Count of numbers in range [ L , R ] with LSB as 0 in their Binary representation | C ++ implementation of the approach ; Function to return the count of required numbers ; If rightmost bit is 0 ; Return the required count ; Driver code ; Call function countNumbers
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countNumbers ( int l , int r ) { int count = 0 ; for ( int i = l ; i <= r ; i ++ ) { if ( ( i & 1 ) == 0 ) { count ++ ; } } return count ; } int main ( ) { int l = 10 , r = 20 ; cout << countNumbers ( l , r ) ; return 0 ; }