Description
Given integers \(n\) and \(k\), find a non-negative sequence \(\{a_n\}\) satisfying the following conditions:
1.
- The binary representation of \(a_1\mid a_2\mid \dots\mid a_n\) has the maximum number of \(1\)s, where \(\mid\) represents the bitwise OR operation.
Multiple tests.
Data Range: \(1\leq n\leq 2\cdot 10^5\), \(1\le k\le 10^9\), \(1\le t\le 10^4\).
Solution
For \(n=1\), there is only one way to construct the sequence, that is to output \(k\) itself.
For \(n>1\), We can easily find out that the answer must be less or equal than \(\log_2 k\), therefore, we only need to find the number of bits in the binary representation of \(k\) (denoted by \(b\)), then the sequence is constructed by:
\(2^{b-1}, k - 2^{b-1}\) and \(n-2\) of \(0\)s.
标签:10,le,1957B,sequence,Solution,mid,Codeforces,find From: https://www.cnblogs.com/hl-fc/p/18163431