题解 | #排列与二进制#
排列与二进制
https://www.nowcoder.com/practice/647fc23dc4e147328cc484e3aeb6cc2a
#include <iostream> using namespace std; int main() { int n, m; while (cin >> n >> m) { if (!n && !m) break; int sum = 0; for (int i = 0; i < m; ++i) { int k = n - i; while (!(k & 1)) { k >>= 1; sum++; } } cout << sum << endl; } }
简洁的位运算