Блог пользователя tobias_tris

Автор tobias_tris, история, 3 года назад, По-английски

Determine whether it is possible to choose X numbers that are powers of 2 and add up to N.

  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

»
3 года назад, скрыть # |
 
Проголосовать: нравится -7 Проголосовать: не нравится

You can check how many bits are set in the number N. if its equal to x then it is possible

»
3 года назад, скрыть # |
← Rev. 4  
Проголосовать: нравится 0 Проголосовать: не нравится

Answer is yes iff sbits(N) is <=X and X<=N.

sbits(x) refers to the number of 1s in the binary representation of x

Proof