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 takes 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
2
4 2
1000 500
Sample Output
1
6
problem-solving ideas: This topic is to find the number of factors, m!/((m-n)!*n!) is equal to the product from the n+1 has multiplied to m divided by the factorial of M-n, that is, the number of factors in n+1 to M minus 1 to m-n number of factors.
Program code:
#include <iostream>
using namespace std;
Main ()
{
int T;
cin>>t;
while (t--)
{
int m,n;
cin>>m>>n;
int r=0,v=0;
for (int i=n+1;i<=m;i++)
{
int s=i;
while (s%2==0)
{
S=S/2;
r++;
}
}
for (int j=1;j<=m-n;j++)
{
int b=j;
while (b%2==0)
{
B=B/2;
v++;
}
}
printf ("%d\n", r-v);
}
return 0;
}
ACM for C (m, n) = m!/((m-n)!n!) The number of zeros at the end of the binary number