poj 2249 Binomial Showdown

这是一道简单求C(n,m)的题:

View Code
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<cmath>

#include<queue>

#include<set>

#include<map>

#include<cstring>

#include<vector>

#include<string>

#define LL long long

using namespace std;

LL Gcd( LL a, LL b )

{

    return b == 0 ? a : Gcd( b , a%b );    

}

LL C( int n , int k )

{

    LL sum1 = 1,sum2 = 1;

    while( k )

    {

        

         sum1 *= k;

         sum2 *= n; 

         LL t = Gcd( sum1 , sum2 );

         sum1 /= t;

         sum2 /= t;

         n--;

         k--;    

    }    

    return sum2;

}

int main(  )

{

    int n,k;

    while( scanf( "%d %d",&n,&k ),n|k )

    {

        k = min( k , n - k );

        if( k == 0 ) puts( "1" );

        else

        {

           printf( "%I64d\n",C( n , k ) );    

        }

    }

    //system( "pause" );

    return 0;

}

 

你可能感兴趣的:(show)