| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
1306怎么wa了
帮忙该一下吧
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
double lnchoose(int n, int m)
{
if (m > n)
{
return 0;
}
if (m < n/2.0)
{
m = n-m;
}
double s1 = 0;
for (int i=m+1; i<=n; i++)
{
s1 += log((double)i);
}
double s2 = 0;
int ub = n-m;
for (int i=2; i<=ub; i++)
{
s2 += log((double)i);
}
return s1-s2;
}
double choose(int n, int m)
{
if (m > n)
{
return 0;
}
return exp(lnchoose(n, m));
}
int main()
{
int n,m;
while(scanf("%d %d",&n,&m) && n && m)
{
double res=choose(n,m);
printf("%d things taken %d at a time is %.lf exactly.\n",n,m,res);
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator