The binomial coefficient C (m, n)Is defined
m!C(m,n) = -------- n!(m-n)!
Given four natural numbers P, Q, R, And S, Compute the result of dividing C (p, q)By C (R, S). The inputinput consists of a sequence of lines. Each line contains four non-negative integer numbers giving values P, Q, R, And S, Respectively, separated by a single space. All the numbers will be smaller than 10,000 P> = QAnd R> = s. The outputfor each line of input, print a single line containing a real number with 5 digits of precision in the fraction, giving the number as described above. you may assume the result is not greater than 100,000,000. sample Input
10 5 14 993 45 84 59145 95 143 92995 487 996 4882000 1000 1999 9999998 4999 9996 4998
Output for sample input
0.12587505606.460551.282230.489962.000003.99960
Question: The question is a combinationC (p, q)/C (R, S); then one can be multiplied by one and divided by one.
m!C(m,n) = -------
n!(m-n)!
Simplified to m-1) * (m-2)... (m-n + 1)/n !; The number of this numerator is the same as that of the denominator;
Then there will be a subscript;
# include <iostream># include <cstdio>using namespace std;int main(){ //freopen("a.txt","r",stdin); int p,q,r,s; while(scanf("%d%d%d%d",&p,&q,&r,&s)!=EOF) { int i,n; double ans=1.0; //if (p - q < q) q = p - q; //if (r - s < s) s = r - s; for(i=1;i<=q||i<=s;i++) { if(i<=q) ans=ans*(p-q+i)/i; if(i<=s) ans=ans/(r-s+i)*i; } printf("%.5lf\n",ans); } return 0;}
Choose and divide