组合数【组合数学】

组合数

链接:组合数

注意:溢出。

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const ll mod = 1e18;
int main(void){
	ll n,k;
	while(cin>>n>>k){ 
		k = min(k,n-k);
		__int128 res = 1;
		int flag = 0;
		for(ll i = 1; i <= k; i++){
			res = res*(ll)(n-i+1)/(ll)i;
			if(res>mod){
				flag = 1;
				break;
			}
		}
		if(flag){
			cout<<mod<<endl;
		}else{
			cout<<(ll)res<<endl;
		}
	}
	return 0;
} 

posted @ 2020-01-03 16:43  Gorgeous11  阅读(76)  评论(0)    收藏  举报