有没有一种方法可以非常快地精确计算大约3.7亿小数位的9^(9^9)?我使用了一个开箱即用的大型算法库(*),花费了16分钟。
(*)我使用了Java BigInteger -- pow()方法:
?- time((_ is 9^(9^9))).
% Up 974,318 ms, GC 9,302 ms, Thread Cpu 962,688 ms (Current 06/01/18
19:54:01)
Yes
?- statistics.
Max Memory 7,635,730,432 Bytes
Used Memory 765,913,440 Bytes
Free Memory 2,891,739,304 Bytes
Uptime 2,466,670 Millis
GC Time 9,315 Millis
Thread Cpu Time 963,812 Millis
Current Time 06/01/18 20:18:37 Java BigInteger实现使用Karatsuba和Toom:
http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/share/classes/java/math/BigInteger.java
额外输出约3.7亿小数位数,如果每位数字使用1毫秒,只需37万毫秒。这是我需要计算上述数字的三分之一,也就是974,318毫秒,没有显示。
发布于 2018-06-06 17:17:34
尝试https://raw.githubusercontent.com/tbuktu/bigint/master/src/main/java/java/math/BigInteger.java,以获得一个改进的BigInteger,一旦整数超过74,000位数,就切换到Schoenhage-Strassen。我的信封背面说,这应该是一个数量级的数量级后,你得到了数亿的数字。
https://stackoverflow.com/questions/50725681
复制相似问题