如何知道n!是否可以表示为三个连续数字的乘法?
How to find out if n! can be expressed as a multiplication of three consecutive numbers?
嘿,我的代码已经走到了这一步
#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 个值来检查,太多了,但这是想法。
相关文章:
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- 在 2D 向量中使用第三个 [ ] 有什么意义?
- 如何通过按下第三个窗口中的按钮,将QString从一个窗口获取到另一个窗口
- 如何知道n!是否可以表示为三个连续数字的乘法?
- 我有三个 getline,但是一旦编译,输入就太多了
- 我遇到了黑客排名中的问题"TWO STRINGS"的三个测试用例的分段错误。原因是什么?
- 有没有更好的方法对C++中的三个整数进行排序?
- 如何检查第三个 API 是否在 Linux 中为 c/c++ 程序创建了一个新线程?
- 为什么 getch 在按下函数或箭头键时返回三个值?
- 使用三个数字比较器进行排序
- 我想在C++代码中比较这三个术语
- 我的动态链接队列在同一输出流中调用时不正确地输出三个返回函数
- 我该如何编码,使计算机知道两个名称条目和三个名称条目之间的区别
- 为什么我需要三个嵌套的大括号来调用赋值运算符,将const引用到二维数组
- 如何通过通用引用或std::forward将这三个c++模板函数合并为一个
- 首先处理第二个和第三个堆与第一个和第二个堆之间的逻辑差异
- 异常处理:如果用户输入不是三个特定字符之一
- 为什么将三个变量与 == 一起比较会计算为 false?
- 重载运算符 new 和运算符 delete 带有三个参数
- 逆转三个连续子范围 [A,B,C] -> [C,B,A] 的有效方法