Description
从m个不同元素中取出n (n ≤ m)个元素的所有组合的个数,叫做从m个不同元素中取出n个元素的组合数。组合数的计算公式如下:
C(m, n) = m!/((m - n)!n!)
现在请问,如果将组合数C(m, n)写成二进制数,请问转这个二进制数末尾有多少个零。
Input
第一行是测试样例的个数T,接下来是T个测试样例,每个测试样例占一行,有两个数,依次是m和n,其中n ≤ m ≤ 1000。
Output
分别输出每一个组合数转换成二进制数后末尾零的数量。
Sample Input
24 21000 500
Sample Output
16
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int bina(int k){
int t=0;
for(int i=1;i<=k;i++){
int x = i;
while(x){
if(x&1) break;
t++;
x/=2;
}
}
return t;
}
int main(){
int c;
int m,n;
cin>>c;
while(c--){
cin>>m>>n;
cout<<bina(m)-bina(m-n)-bina(n)<<endl;
}
return 0;
}