Problem Description
Are you excited when you see the title "AC" ? If the answer is YES , AC it ;
You must learn these two combination formulas in the school . If you have forgotten it , see the picture.
Now I will give you n and m , and your task is to calculate the answer .
You must learn these two combination formulas in the school . If you have forgotten it , see the picture.
Now I will give you n and m , and your task is to calculate the answer .
Input
In the first line , there is a integer T indicates the
number of test cases.
Then T cases follows in the T lines.
Each case contains a character 'A' or 'C', two integers represent n and m. (1<=n,m<=10)
Then T cases follows in the T lines.
Each case contains a character 'A' or 'C', two integers represent n and m. (1<=n,m<=10)
Output
For each case , if the character is 'A' , calculate
A(m,n),and if the character is 'C' , calculate C(m,n).
And print the answer in a single line.
And print the answer in a single line.
Sample Input
2
A 10 10
C 4 2
Sample Output
3628800
6
1 #include <stdio.h> 2 3 int jieCheng(int number); 4 5 int main(){ 6 int T; 7 char c; 8 int n; 9 int m; 10 int n_jieCheng; 11 int m_jieCheng; 12 int n_m_jieCheng; 13 int result; 14 15 scanf("%d",&T); 16 17 while(T--){ 18 getchar(); 19 20 scanf("%c%d%d",&c,&n,&m); 21 22 n_jieCheng=jieCheng(n); 23 m_jieCheng=jieCheng(m); 24 n_m_jieCheng=jieCheng(n-m); 25 26 if(c=='A') 27 result=n_jieCheng/n_m_jieCheng; 28 29 else 30 result=n_jieCheng/(m_jieCheng*n_m_jieCheng); 31 32 printf("%d ",result); 33 } 34 return 0; 35 } 36 37 int jieCheng(int number){ 38 int result; 39 int i; 40 41 result=1; 42 43 for(i=1;i<=number;i++) 44 result*=i; 45 46 return result; 47 }