Calculate x by x in the most optimal way

Possible duplicate:
The most efficient way to implement the integer power function pow (int, int)

I know this question is pretty simple, but my requirement is that I want to calculate x for power x, where x is a very large number in the best possible optimization. I am not a mathematician and therefore need help to figure out the best way possible.

In java we can use BigInteger, but how to optimize the code? Any specific optimization approach?

Also using recursion will be a large x value, makes the code slow and error prone?

For example: 457474575 raise to power 457474575

+3
source share
3 answers

, , BigInteger? 3961897696 !

, , - . x x, x x. , e x exp(x), .

+12

:

x^1*x^1=x^2
x^2*x^2=x^4
etc...
x^x = x^(x/2)*x^(x/2)*remainder
+1

((BigInteger) 457474575) .pow (457474575);

+1
source

All Articles