I want to calculate the power of huge number using C#
I've used this code. it works but I want to calculate it in less time.
BigInteger a;
a = Math.Pow(4100000000,4100000000);
Console.Writeline(a);
I want to calculate the power of huge number using C#
I've used this code. it works but I want to calculate it in less time.
BigInteger a;
a = Math.Pow(4100000000,4100000000);
Console.Writeline(a);
You can test this but not sure if this is faster than the native function Math.Pow
using System;
public class GFG{
static float power(float x, int y)
{
float temp;
if( y == 0)
return 1;
temp = power(x, y/2);
if (y % 2 == 0)
return temp * temp;
else
{
if(y > 0)
return x * temp * temp;
else
return (temp * temp) / x;
}
}
// Program to test function power
public static void Main()
{
float x = 2;
int y = -3;
Console.Write(power(x, y));
float x = 4100000000;
int y = 4100000000;
Console.Write(power(x, y));
}
}
Time Complexity: O(logn)
Space Complexity: O(1)
Algorithmic Paradigm: Divide and conquer.