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:如果是高精度怎么办?能不能提供点代码?In Reply To:如果是高精度怎么办?能不能提供点代码? Posted by:zhyzhang at 2009-05-20 21:47:50 比较弱 #include <stdio.h> int a[200]; int size = 0, cur, last; void mul(int b){ int cf = 0; for(int i = 0; i < 200; i++){ a[i] = a[i]*b+cf; cf = a[i]/10; a[i] %= 10; } for(int i = size; i < 200; i++) if(a[i] != 0) size++; } void div(int b){ last = 0; int i; for(i = size-1; i >= 0; i--){ cur = last*10+a[i]; if(cur < b){ a[i] = 0; last = cur; } else{ a[i] = cur/b; last = cur%b; } } for(i = size-1; i >= 0; i--) if(a[i] != 0) break; size = i+1; } int main(){ int n, m; while(1){ scanf("%d%d", &n, &m); if(n == 0 && m == 0) break; for(int i = 0; i < 200; i++) a[i] = 0; a[0] = size = 1; for(int i = n-m+1; i <= n; i++) mul(i); for(int i = 2; i <= m; i++) div(i); printf("%d things taken %d at a time is ", n, m); for(int i = size-1; i >= 0; i--) printf("%d", a[i]); printf(" exactly.\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator