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 |
救命啊!!!!!实在想不出怎么错啦#include <iostream.h> int main(void){ int n, k, *a, *b, sum, i, j; cin >> n >> k; while(n!=0 && k!=0){ if(k==0 || k == n) cout << 1<< endl; else if(k ==1 || k == n-1) cout << n << endl; else{ if(k>n/2) k = n-k; a = new int[k]; b = new int[k]; for(i=0; i<k; ++i){ a[i] = n-i; b[i] = i+1; } sum = 1; for(i=0; i<k; ++i){ for(j=k-1; j>0; j--){ if(a[i]%b[j] == 0 && b[j]!=1){ a[i] /= b[j]; b[j] = 1; } } sum *= a[i]; for(j=k-1; j>0; j--){ if(sum%b[j] == 0 && b[j]!=1){ sum /= b[j]; b[j] = 1; } } } delete []a; delete []b; cout << sum << endl; } cin >> n >> k; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator