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 |
为何会WA呢?大惑不解#include <stdio.h> int gcd(int a, int b) { int i = a % b; if(i == 0) { return b; } else { return gcd(b, i); } } void dividebygcd(long &a, long &b) { long gcd_value = gcd(a, b); a /= gcd_value; b /= gcd_value; } long combination(int m, int n) { long denominator = 1; long numerator = 1; long multi = 1; long divide = 1; if(m > (n / 2)) { m = n - m; } if(m == 0) { return 1; } while(m != 0) { multi = n--; divide = m--; dividebygcd(multi, divide); dividebygcd(multi, denominator); dividebygcd(divide, numerator); denominator *= divide; numerator *= multi; } return (numerator / denominator); } int main(int argc, char * argv[]) { int m, n; do { scanf("%d", &n); scanf("%d", &m); if(m == 0 && n == 0) { return 0; } printf("%d things taken %d at a time is %d exactly\n",n, m, combination(m, n) ); }while(1); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator