| UFBA Selection Contest 2026 |
|---|
| Закончено |
During a cultural fair at UFBA, a group of students is preparing souvenir ribbons inspired by the famous fitinhas do Bonfim. Each ribbon design is encoded by an integer, and its binary representation tells which ornaments are present: a bit equal to $$$1$$$ means that ornament is used, while a bit equal to $$$0$$$ means it is not. Therefore, the total number of ornaments in a design is exactly the number of bits set to $$$1$$$.
Professor Rubis wants to approve the next design after a given code $$$N$$$, but he is strict about one detail: the new design must contain exactly $$$M$$$ ornaments. Among all valid integers strictly greater than $$$N$$$, he wants the smallest possible one, so that the next approved design is as close as possible to the current code.
Help him find that next ribbon code.
The input contains two integers $$$N$$$ and $$$M$$$ ($$$0 \leq N \leq 10^{18}$$$, $$$1 \leq M \leq 60$$$).
Output the code of the next approved ribbon design.
10 2
12
7 1
8
13 3
14
| Название |
|---|


