-8

How could i deal with this?

100^100000000000

to show it i divide it by 10^x and print the result, but it always print the max range for an int (long or wathever) divided by this 10^x, not the actual result.

Thank you.

Pd: In Java if its possible please.

Sampudon
  • 85
  • 1
  • 8

1 Answers1

0

You could use: BigInteger and BigDecimal classes for this kind of computations;

But the power algorithm for such a big power numbers you need to implement.

Something like this:

public static void main(String[] args) {
    System.out.println(pow("100","100000000000"));
}

private static BigInteger pow(String b, String p) {
    BigInteger toPow = new BigInteger(b);
    BigInteger pow = new BigInteger(p);
    while (pow.compareTo(BigInteger.ONE)!=0) {
        pow = pow.subtract(BigInteger.ONE);
        toPow = toPow.multiply(toPow);
    }
    return toPow;
}
Krzysztof Cichocki
  • 6,294
  • 1
  • 16
  • 32