02 November 2015

uva 369

/***
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
verdict: accepted
***/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cctype>
#include<sstream>
#include<stdlib.h>
#include<map>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))

long long nCr(long long n, long long r)
{
    long long i,res=1;
    if(n-r<r)
    {
        r=n-r;
    }
    for(i=1; i<=r; i++,n--)
    {
        res =(res*n)/i;

    }
    return res;
}

int main()
{
    long long n,r,ans;
    while(2==scanf("%lld%lld",&n,&r))
    {
        ans=1;
        if(n==0 && r==0)
        {
            break;
        }
        ans=nCr(n,r);
        printf("%lld things taken %lld at a time is %lld exactly.\n",n,r,ans);
    }
    return 0;
}

No comments:

Post a Comment

UVA 10679 - I Love Strings!!