Question one hundred and thirty-one: number of combinations

Source: Internet
Author: User

Description


Evaluate C (N, M), that is, find the number of combinations of N numbers in M number.


Input


The first line is a positive integer T (T <= 10), indicating that there are T groups of test data. Line 2 ~ Row T + 1 has two positive integers N, M (1 <= N, M <= 20 ).


Output


Input N, M in each group, and output a row. The row has a number, which is the C (N, M) value.


Sample Input

 


2
3 5
1 20


Sample Output

 


10

20


[Plain] # include <stdio. h>
 
_ Int64 fac (int );
 
Int main ()
{
Int num;
Int n;
Int m;
Scanf ("% d", & num );
 
While (num --)
{
Scanf ("% d", & n, & m );
 
Printf ("% d", fac (m)/fac (n)/fac (m-n ));

If (num> 0)
{
Printf ("\ n ");
}
}
 
Return 0;
}
 
_ Int64 fac (int)
{
Int I;
_ Int64 sum;
 
Sum = 1;
If (a = 0)
{
Sum = 1;
}
Else
{
For (I = 1; I <= a; I ++)
{
Sum * = I;
}
}
 
Return sum;
}

# Include <stdio. h>

_ Int64 fac (int );

Int main ()
{
Int num;
Int n;
Int m;
Scanf ("% d", & num );

While (num --)
{
Scanf ("% d", & n, & m );

Printf ("% d", fac (m)/fac (n)/fac (m-n ));

If (num> 0)
{
Printf ("\ n ");
}
}

Return 0;
}

_ Int64 fac (int)
{
Int I;
_ Int64 sum;

Sum = 1;
If (a = 0)
{
Sum = 1;
}
Else
{
For (I = 1; I <= a; I ++)
{
Sum * = I;
}
}

Return sum;
}

 
 

Related Article

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.