Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何找出n!可以表示为三个连续数字的乘法吗?_C++ - Fatal编程技术网

C++ 如何找出n!可以表示为三个连续数字的乘法吗?

C++ 如何找出n!可以表示为三个连续数字的乘法吗?,c++,C++,嘿,我的代码已经走了这么远了 现在我需要检查阶乘是否可以是三个连续数字的乘法,我真的被困在这个问题上了,提前谢谢你的帮助 我认为除了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

嘿,我的代码已经走了这么远了


现在我需要检查阶乘是否可以是三个连续数字的乘法,我真的被困在这个问题上了,提前谢谢你的帮助

我认为除了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个值来检查,这太多了,但这是我的想法。

为什么你被卡住了?从检查数字是否等于1*2*3开始,然后尝试下一组连续数字,直到找到或没有找到这些因素。然后试着找出你要检查的最大数字是什么。有选择地尝试找到一个比1*2*3更好的第一次猜测,通过从1到n的所有可能数字循环,找出哪一个匹配,如果它找到一个。。。打破循环……你用一个for循环检查它吗?不知道你在问什么,或者这与C++有什么关系。你需要检查什么?如果有任何a>1,使得n!==a-2*a-1*a?请注意,由于阶乘增长非常快,并且int可以存储的值有限制,因此阶乘函数将溢出许多值。假设int有32位,factorialn将仅对n有效。其中为6!=8*9*10也是:
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
}