找到一个真正强大的数字 [英] Finding really big power of a number
问题描述
我正在为学生创建一个小游戏,在一个地方,它必须显示2 7830457 +1的价值
I am creating a small game for students, and in a place, it has to display the value of 27830457+1
如果数字不是那么大,我可以调用BigInteger的pow()方法。由于数量很大,这种方法毫无用处。我怎样才能找到这种数字的巨大力量?请帮忙!
I can call BigInteger's pow() method if the number is not this much big. Since the number is very big, that method is useless. How can I find the HUGE power of this kind of numbers? Please help!
推荐答案
我不知道你为什么认为 BigInteger
不能达到这个目的:
I don't know why you think BigInteger
isn't up to this:
import java.math.BigInteger;
public class Test {
public static void main(String[] args) throws Exception {
BigInteger big = BigInteger.valueOf(2)
.pow(7830457)
.add(BigInteger.ONE);
System.out.println(big);
}
}
这需要一点时间(特别是字符串转换时间为结束),但这是完全合理的。
It takes a little while (particularly the string conversion at the end), but it's perfectly reasonable.
正如彼得所说,转移 ONE
左7830457更加整洁,记住您。我认为它不太清楚 - 当然它在字符串转换部分没有帮助。
As Peter noted, shifting ONE
left 7830457 is much neater, mind you. I'd argue it's a bit less clear - and of course it doesn't help in the string conversion part.
编辑:几乎所有的时间花在了字符串转换。它最后在我的盒子上完成了。我再也看不到它的开始了,但它以......结尾。
Almost all of the time is spent in the string conversion. It finished in the end on my box though. I can't see the start of it any more, but it ends with...
08570502260645006898157834607641626568029302766491883299164453304032280181734737
79366998940913082443120328458954436211937775477966920836932628607888755839700303
873
这篇关于找到一个真正强大的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!