标签:ide lang color and for gif scanf code end
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 22692 | Accepted: 6925 |
Description
Input
Output
Sample Input
4 2 10 5 49 6 0 0
Sample Output
6 252 13983816
题意:输入n,k求C(n,k)。
挺无聊的一题,因为答案在2^32内,直接开long long 然后暴力就行了。
AC code:
#include<cstdio> using namespace std; typedef long long int64; int64 C(int64 n,int64 k) { int64 a=1,b=1; for(int i=1;i<=k;i++) { a*=(n+1-i); b*=i; if(!(a%b)){ a/=b; b=1; } } return a/b; } int main() { //freopen("input.txt","r",stdin); int64 n,k; while(~scanf("%lld%lld",&n,&k)&&n+k) { if(k>n/2) k=n-k; printf("%lld\n",C(n,k)); } }
标签:ide lang color and for gif scanf code end
原文地址:https://www.cnblogs.com/cautx/p/11404384.html