如何知道n!是否可以表示为三个连续数字的乘法?

How to find out if n! can be expressed as a multiplication of three consecutive numbers?

本文关键字:连续 三个 数字 何知道 是否 表示      更新时间:2023-10-16

嘿,我的代码已经走到了这一步

#include 使用命名空间标准;
int factorial(int n);
int main()
{
int n;
cout << "Enter a positive integer: ";
cin >> n;
cout << "Factorial of " << n << " = " << factorial(n);
return 0;
}
int factorial(int n)
{
if(n > 1)
return n * factorial(n - 1);
else
return 1;
}

现在我需要检查阶乘是否可以是三个连续数字的乘法,我真的很坚持,提前感谢您的帮助!!

我不认为除了3!4!5!有这样的数字。

不过,如果您想查找这些数字:

int hint = std::pow(fact, 1./3.);
for (int trial = -10;, trial < 11; ++trial)
{
// check if (hint + trial - 1) * (hint + trial) * (hint + trial + 1) is equal to your result
}

我用 21 个值来检查,太多了,但这是想法。