Prashant Prashant - 2 months ago 11
C Question

How to calculate 2 to the power 10000000

How to calclute 2 to the power 10000000 without crashing the compiler. What shoud be data type for extramily big integer in c/c++.

Answer

Store the digits in an int array where each location of the array denotes one digit. Then multiply them repetitively. That way you will get the answer with out crashing the compiler.

Well you need 302 locations for that. And the multiplication is simply the one that we do in grade classes. You have implement it in coding.

Little bit of code

int d[400];

for(int i=0;i<399;i++)
   d[i]=0;

d[0]=1;

int carry=0;
int temp=0;
for(int j=0;j<=999;j++)
{
   carry=0;
   temp=0;
   for(int i=0;i<=399;i++)
   {
      temp=d[i]*2+carry;
      d[i]= temp%10;
      carry = temp/10;
   }
}
print d[0..399] in reverse order trimming zeroes.