(高精度运算)计算2的N次方。N <= 10000
作者:
Yutong_Bao
,
2021-10-30 17:24:00
,
所有人可见
,
阅读 442
(高精度运算)计算2的N次方。N <= 10000
//Express Edition
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n,x ;
cin >> n;
x = pow(2,n);
cout << x;
return 0;
}
// Normal Edition
#include <iostream>
#include <cmath>
using namespace std;
const int N = 3010;
int main()
{
int a[N] = {1};
int n;
cin >> n;
int m = 1; //m为进位
for(int i =0; i < n; i++)
{
int t = 0;
for(int j = 0; j<m ;j++)
{
t+=a[j] *2;
a[j] = t% 10;
t /= 10;
}
if (t) a[m++] = 1;
}
for (int i = m-1;i >=0; i--) cout << a[i];
cout <<endl;
return 0;
}