反向析因 [英] Reverse factorial
问题描述
好了,我们都知道,如果N给出很容易计算出n个!但是,我们的反?
N!给予,你要找到N - 这可能吗?我很好奇。
- 设置
X = 1
。 - 生成
F = X!
- 为:F =输入?如果是,则
X
是N - 如果没有,则设置
X = X + 1
,然后在#2重新开始。
您可以通过使用 F
的previous结果来计算新 F
(优化新F =新的X *老˚F
)。
它一样快会相反的方向,如果不是更快,因为除法一般需要长于乘法。一个给定的阶乘 A!
保证具有小于 A
所有整数的因素除了A,所以你' ð花同样多的时间分解出来的那些,你会只计算运行阶乘。
Well, we all know that if N is given it's easy to calculate N!. But what about the inverse?
N! is given and you are about to find N - Is that possible ? I'm curious.
- Set
X=1
. - Generate
F=X!
- Is F = the input? If yes, then
X
is N. - If not, then set
X=X+1
, then start again at #2.
You can optimize by using the previous result of F
to compute the new F
(new F = new X * old F
).
It's just as fast as going the opposite direction, if not faster, given that division generally takes longer than multiplication. A given factorial A!
is guaranteed to have all integers less than A
as factors in addition to A, so you'd spend just as much time factoring those out as you would just computing a running factorial.
这篇关于反向析因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!