简单求组合数,直接运用公式。注意C(n,k)=C(n,n-k)。
#include <iostream> #include <cstdio> #include <algorithm> #define LL __int64 using namespace std; LL myc(LL n, LL r){ LL sum=1; for(LL i=1;i<=r;i++) sum=sum*(n+1-i)/i; return sum; } int main(){ LL n,r; while(scanf("%I64d%I64d",&n,&r),n||r){ r=r>n-r?n-r:r; LL res=myc(n,r); printf("%I64d\n",res); } return 0; }
时间: 2024-10-04 08:00:58