Reputation: 469
Here i is a number between 0 and n And y is any random number
//brute force
//say y is 49
count=0;
for(int i=0;i<=49;i++){
if((i&y)==i)
count++
}
cout<<count;
Also I would like to know what are those numbers ?
Upvotes: 0
Views: 115
Reputation: 12047
Let b be the number of set bits in y.
Then,
2b
is the number of numbers that satisfy the property.
The numbers are those for which all bits that are not set in y are also not set.
Upvotes: 3