反向析因 [英] Reverse factorial

查看:145
本文介绍了反向析因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我们都知道,如果N给出很容易计算出n个!但是,我们的反?

N!给予,你要找到N - 这可能吗?我很好奇。

解决方案
  1. 设置 X = 1
  2. 生成 F = X!
  3. 为:F =输入?如果是,则 X 是N
  4. 如果没有,则设置 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.

解决方案

  1. Set X=1.
  2. Generate F=X!
  3. Is F = the input? If yes, then X is N.
  4. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆