English 中文(简体)
BigInteger.pow(BigInteger)?
原标题:BigInteger.pow(BigInteger)?

我在 Java玩.,想看到我能做些什么。 我的理解是,只要我的计算机有足够的记忆来持有这样的数字,大脑能够保持一定的规模?

我的问题是BigInteger。 pow 只接受一只 in子,而不是另一个大脑,这意味着我只能使用多达2 147 483 647个大体。 是否可能使用大负债类?

BigInteger.pow(BigInteger)

感谢。

问题回答

BigInteger的基本实施限于(2^31-1),即32比值。 接近2°36轨道。 你们将需要8 GB的记忆来储存它,并需要many倍的记忆,以便开展与String(String)这样的行动。

BTW:你永远无法读到这样的数字。 如果你试图将其印成册,就需要一生时间阅读。

请了解以前的答复和评论,并理解为什么不应在生产水平应用上尝试这样做。 下面是一份只能用于测试的工作解决办法:

Exponent greater than or equal to 0

BigInteger pow(BigInteger base, BigInteger exponent) {
    BigInteger result = BigInteger.ONE;
    for (BigInteger i = BigInteger.ZERO; i.compareTo(exponent) != 0; i = i.add(BigInteger.ONE)) {
        result = result.multiply(base);
    }
    return result;
}

这将有利于积极和消极的基础。 您不妨处理0至。 根据你们的需要,因为从技术上来说,这并不明确。

Exponent can be both positive or negative

BigDecimal allIntegersPow(BigInteger base, BigInteger exponent) {
    if (BigInteger.ZERO.compareTo(exponent) > 0) {
        return BigDecimal.ONE.divide(new BigDecimal(pow(base, exponent.negate())), 2, RoundingMode.HALF_UP);
    }
    return new BigDecimal(pow(base, exponent));
}

这重新使用了第一种方法,即把2个小数点的比戈麦尔重新归来,你可以按照你的需求确定比额表和环绕模式。

同样,在现实生活中,在生产层面,你不应这样做。

java获胜,请你做大白。 Pow(BigInteger)但是,你只能把它放在一只 lo子里,看一片 Ar子被扔出,或发现由于失去记忆而出现其他一些错误。

I can suggest you make use of BigInteger modPow(BigInteger exponent, BigInteger m)

附录一

• 选择一个大型的P >>>X^Y和 do Z = X.modPow(Y,P);





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签