Sunday, February 27, 2011

369 - Combinations


#include<stdio.h>
#include<cmath>
int main()
{
   
    register long int m,n,res,i,k,t;
    register double logm,logn;
    //freopen("in.txt","r",stdin);
    while(scanf("%ld%ld",&m,&n)&&(m||n))
    {
        k=m-n,t=n;
        if(k>n)
            t=k;
        logm=logn=k=0;
        for(i=t+1;i<=m;i++)
        {
            logm=logm+log(i);
            logn=logn+log(++k);
        }
        res=exp(logm-logn)+0.5;
        printf("%ld things taken %ld at a time is %ld exactly.\n",m,n,res);
    }
    return 0;
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.