Calculate power of large numbers mathematically?

406 Views Asked by At

Is there a short-hand method to find the value of a number with a large power. For example : 1024^2048

1

There are 1 best solutions below

0
On

Usually, you do not want large power exact value, but mod power.

C# examples (it's StackOverflow, so a kind code is expected):

// Exact value
BigInteger a = BigInteger.Pow(1024, 2048);
// Mod Power (a^b mod 3) much more popular
BigInteger b = BigInteger.Pow(1024, 2048, 7);  // <- mod 7