When there are 2 ^ i bottles, a bottle can be synthesized.
The n converted to binary, there are several several bottles 1 can be synthesized, when more than k, on the plus number (plus 4 to 1100) of 1 least significant bit, and then continues to determine.
#include <iostream>
using namespace std;
typedef long long ll;
ll n, k, ans;
int setcount(ll x)
{
int ret = 0;
for (; x; x -= x & -x) ret++;
return ret;
}
int main(void)
{
cin >> n >> k;
while (setcount(n) > k) {
ans += n & -n;
n += n & -n;
}
cout << ans;
return 0;
}