Description
The number of all combinations of n (n ≤ m) elements taken from m different elements is called the number of combinations of n elements taken from m different elements. The formula for calculating the number of combinations is as follows:
C (m, n) = m!/((m - n)! N!)
Now, if you write the combined number C (m, n) as a binary number, how many zeros are there at the end of the binary number?
Input
The first line is the number of test samples T, followed by the T test sample, each test sample occupies a row, there are two numbers, followed by m and n, where n ≤ m≤ 1000.
Output
Outputs the number of each combined number converted to the end zero after the binary number.
Sample Input
Sample Output
#include <iostream>using namespacestd;intMain () {intT,a,b;cin>>T; while(t--) {cin>>a>>b; intx=0, y=0; for(inti=a-b+1; i<=a;i++){ intt=i; while(t>1){ if(t%2==0&&t!=0) x + +; Else Break; T/=2; } } for(intI=2; i<=b;i++){ intt=i; while(t>1){ if(t%2==0&&t!=0) y++; Else Break; T/=2; }} cout<<x-y<<Endl; } return 0;}
View Code
Number of combinations