Number of combinations

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.