Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
用__int64和用double都能过,因为题目说了输出结果 32位的最大值,所以当n==100时候,测试数据k最多到12/**************************************************** 用64可以这样写 ****************************************************/ #include<iostream> using namespace std; __int64 kin_Cnk(int n,int k){ __int64 sum1 = 1; __int64 sum2 = 1; int time = k; while(time--){ sum1 *= n--; if(sum1%k==0){ sum1 /= k--; } } while(k) sum2 *= k--; return sum1 / sum2; } int main() { int n,k,temp; __int64 sum; while(scanf("%d%d",&n,&k)){ if(!n && !k) break; if(k> n/2) temp = n - k; else temp = k; sum = kin_Cnk(n,temp); printf("%d things taken %d at a time is %I64d exactly.\n" ,n,k,sum); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator