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 |
Re:算错了,连100 12这种数据都不可能出现 这已经是结果是64位的数据了In Reply To:用__int64和用double都能过,因为题目说了输出结果 32位的最大值,所以当n==100时候,测试数据k最多到12 Posted by:kin2141539 at 2008-09-12 18:28:30 > /**************************************************** > > > 用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