1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Author: Bartek Knapik

#include <cstdio>

inline int bitcnt(int n)
{
    if (n == 0) return 0;
    if (n & 1)
        return 1 + bitcnt(n / 2);
    return bitcnt(n / 2);
}

int main()
{
    int N, ans, i, cnt, skip;
    scanf("%d", &N);

    ans = 0;
    i = 1;

    while (true)
    {
        ans += bitcnt(i);
        if (ans >= N)
        break;
        i++;
    }

    cnt = i;
    skip = -1;

    if (ans > N)
        while (i)
        {
            if (bitcnt(i) == ans - N)
            {
                skip = i;
                cnt--;
                break;
            }
            i--;
        }

    printf("%d\n", cnt);
    if (skip > 0) cnt++;
    for (int k = cnt; k > 0; --k)
        if (k != skip) printf("%d ", k);
    printf("\n");

    return 0;
}