我写了下面的代码来计算 n 个 testCount 值的 nCr。它似乎对我的价值观很好,但黑客地球的测试用例失败了,问题链接http://www.hackerearth.com/problem/golf/minimal-combinatorial/description/ 谁能告诉我我的逻辑中潜在的谬误是什么
`#include <iostream>
using namespace std;
int main()
{
int testCount;
int n , r;
cin >> testCount;
for (int i = 0 ; i < testCount ; i++)
{
long int a=1;
long int b=1;
long int c=1;
cin >> n;
cin >> r;
for (int i = n ; i > 1 ; i--)
{
a = a * i;
}
for (int i = n-r; i >= 1 ; i--)
{
b=b*i;
}
for (int i=r;i >=1;i--)
{
c=c*i;
}
long int result=a/(b*c);
cout << result<<"\n";
}
return 0;
}
` 简化分子和分母的情况
`#include <iostream>
using namespace std;
int main()
{
int testCount;
int n , r;
cin >> testCount;
for (int i = 0 ; i < testCount ; i++)
{
long int numerator=1;
long int denominator=1;
cin >> n;
cin >> r;
for (int i = n ; i > r ; i--)
{
numerator = numerator * i;
}
for (int i = n-r; i >= 1 ; i--)
{
denominator=denominator*i;
}
long int result=numerator/denominator;
cout << result;
}
return 0;
} `