这里给出我写的代码,这个代码无法通过所有的评测点,大部分运行超时
long long cnm(int n, int m) { int i; long long sum = 1; int k = 1; if (m > n / 2) m = n - m; for ( i = n - m + 1; i <= n; i++) { sum *= (long long)i; while (k <= m && sum % k == 0) { sum /= (long long)k; k++; } } return sum; } #includeint main() { int i, n, j, count = 0; scanf("%d", &n); for (i = 2; i <= 100000000; i++) { for (j = 0; j <= i; j++) { count++; if (cnm(i, j) == n) goto begin; } } begin: if(n>1)printf("%d", count+3); else printf("1"); return 0; }
如需正确答案,请自行搜索
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)