Produce solutions such that $k$&$x$ $=$ $k$,in a range ($0$,$n$)

21 Views Asked by At

How to efficiently generate all numbers within $0,1,2...n$.
(very large $n$).
Such that for a fixed $x$ and $k$ ($0<=k<=n$), $k$&$x$=$k$.
It is easily found out that all the bits with value $1$ in $k$ is also $1$ in $x$.
But I have trouble computing all of them.
Do I have to consider each and every bit which needs to be changed to get all the possibilities?Any other efficient way? Also I certainly dont want to check with all of $n$.