#abc269c. C - Submask

    ID: 3758 传统题 1000ms 256MiB 尝试: 129 已通过: 27 难度: 7 上传者: 标签>来源atcoder基础算法递归计算机基础二进制其他位运算

C - Submask

Score : 300300 points

问题陈述

给定一个非负整数 NN。按升序打印满足以下条件的所有非负整数 xx

  • xx 的二进制表示中包含数字 11 的位置集合是 NN 的二进制表示中包含数字 11 的位置集合的子集。
    • 即,对于每一个非负整数 kk,下列条件成立:如果 xx 中在 "2k2^k" 位置上的数字为 11,那么 NN 中在 2k2^k 位置上的数字也为 11

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a non-negative integer NN. Print all non-negative integers xx that satisfy the following condition in ascending order.

  • The set of the digit positions containing 11 in the binary representation of xx is a subset of the set of the digit positions containing 11 in the binary representation of NN.
    • That is, the following holds for every non-negative integer kk: if the digit in the "2k2^ks" place of xx is 11, the digit in the 2k2^ks place of NN is 11.

Constraints

  • NN is an integer.
  • 0N<2600 \le N < 2^{60}
  • In the binary representation of NN, at most 1515 digit positions contain 11.

Input

The input is given from Standard Input in the following format:

NN

Output

Print the answer as decimal integers in ascending order, each in its own line.

Sample Input 1

11

Sample Output 1

0
1
2
3
8
9
10
11

The binary representation of N=11(10)N = 11_{(10)} is 1011(2)1011_{(2)}.
The non-negative integers xx that satisfy the condition are:

  • 0000(2)=0(10)0000_{(2)}=0_{(10)}
  • 0001(2)=1(10)0001_{(2)}=1_{(10)}
  • 0010(2)=2(10)0010_{(2)}=2_{(10)}
  • 0011(2)=3(10)0011_{(2)}=3_{(10)}
  • 1000(2)=8(10)1000_{(2)}=8_{(10)}
  • 1001(2)=9(10)1001_{(2)}=9_{(10)}
  • 1010(2)=10(10)1010_{(2)}=10_{(10)}
  • 1011(2)=11(10)1011_{(2)}=11_{(10)}

Sample Input 2

0

Sample Output 2

0

Sample Input 3

576461302059761664

Sample Output 3

0
524288
549755813888
549756338176
576460752303423488
576460752303947776
576461302059237376
576461302059761664

The input may not fit into a 3232-bit signed integer.

update @ 2024/3/10 11:20:52