https://www.luogu.com.cn/problem/P1582
#include <bits/stdc++.h> using namespace std; #define int long long int n,k; //取出1的个数 int check(int x){ int c = 0; for(;x;x -= x & -x){ c++; } return c; } int ans; signed main(){ ios::sync_with_stdio(0); cin >> n >> k; while(check(n) > k){ ans += n & -n; n += n & -n; } cout << ans; return 0; }