题解 | 排列与二进制
排列与二进制
https://www.nowcoder.com/practice/647fc23dc4e147328cc484e3aeb6cc2a
#include <iostream>
using namespace std;
//二进制包含几个末尾0取决于他包含几个因子2
//也就是要找n-m+1~n中包含几个因子2
int f(int n,int x){
//求n的阶乘中包含几个质因子x
int res = 0;
while(n)res+=n/2,n/=2;
return res;
}
int main() {
int m, n;
while (cin >> n >> m) {
if(n==0&&m==0)break;
cout<<f(n,2)-f(n-m,2)<<endl;
}
}
// 64 位输出请用 printf("%lld")