You are not logged in. Please login at to post your questions!


Natural number k satisfying k & x = k

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

asked 16 Jan, 17:03

rds_98's gravatar image

accept rate: 9%

SOS dp. Read the codeforces article.

(16 Jan, 18:15) vijju123 ♦♦5★

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


answered 16 Jan, 18:20

abdullah768's gravatar image

accept rate: 17%

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


answered 16 Jan, 23:47

l_returns's gravatar image

accept rate: 26%

edited 16 Jan, 23:49

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 16 Jan, 17:03

question was seen: 432 times

last updated: 16 Jan, 23:49