Natural number k satisfying k & x = k

How do I find all natural numbers k satisfying k & x == k for some Natural Number x?

You can just go through the sub-optimal solution mentioned here:

3 Likes

you can convert the number x into binary form i.e 15=1+2+4+8 and 13=1+4+8
and make array of all these numbers i.e array for 15={1,2,4,8} and array for 13 will be {1,4,8}
and the find the subsets of this array… and just add elements of each of them… so 15 will update all elements from 1 to 15 as all numbers can be computed using elements of that array…
EDIT: well, there may be another optimised soln about which i am not aware

1 Like

SOS dp. Read the codeforces article.