我尝试使用标准迭代算法来计算 n 次方根。
例如 (111^123)^(1/123)。
标准算法计算基数的高功率(在本例中为 111^123),这需要花费大量时间。这里给出算法http://en.wikipedia.org/wiki/Nth_root_algorithm
但是,我注意到使用 double 执行相同的操作所需的时间不到一毫秒。所以很明显他们使用了一些聪明的想法。有什么提示吗?
最佳答案
However, I noticed that the same thing using double takes less than a millisecond. So obviously they use some smart ideas.
不是真的。 double
只是精度有限,所以它基本上只需要计算结果的最高有效 52 位,可以跳过其余的计算。当然,在硬件中实现这一点也有帮助。
关于java - 计算大根 : bigdecimal/java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2128100/