链接:click here
题意:
In how many ways can you choose k elements out of n elements, not taking order into account? Write a program to compute this number.
给你整数n和k,让你求组合数c(n,k)。
代码:
#include <cstdio> #include <cstring> #include <math.h> typedef long long LL; LL ans,n,k; int main() { while(scanf("%lld%lld",&n,&k),n) { ans=1; if(k == 0) { printf("1\n"); continue; } k=n-k>k?k:n-k; //if(k>n-k)k=n-k; for(int i=1; i<=k; i++) { ans=ans*(n-i+1)/i; } printf("%lld\n",ans); } return 0; }
时间: 2024-10-05 23:27:21