如何计算2到功率10000000 [英] How to calculate 2 to the power 10000000

查看:143
本文介绍了如何计算2到功率10000000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在没有崩溃编译器的情况下将2加到电源10000000。在c / c ++中为外部大整数的数据类型是什么。

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

推荐答案

将数字存储在一个int数组中,数组表示一位数字。然后重复地乘以它们。这样你就可以得到答案,而不要碰撞编译器。

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.

那么你需要302个位置。而且乘法只是我们在班级中所做的。你在编码中实现了它。

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.

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.

这篇关于如何计算2到功率10000000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆