题目描述
编程精确计算2的N次方。(N是介于100和1000之间的整数)。
输入
正整数N (100≤N≤1000)
输出
2的N次方
样例输入
200
样例输出
1606938044258990275541962092341162602522202993782792835301376
#include<iostream> #define MAXNUM 1000 using namespace std; int arr[MAXNUM]; int main() { int n,index; cin>>n; index=0; for(int i=0;i<MAXNUM;i++) { arr[i]=0; } arr[0]=2; for(int i=1;i<n;i++) { int jinwei=0; for(int j=0;j<=index;j++) { int temp=1; if(j==0) { temp=arr[j]*2; if(temp>=10) { jinwei=1; } } else { temp=arr[j]*2; if(jinwei==1) { temp=temp+1; } if(temp>=10) { jinwei=1; } else { jinwei=0; } } arr[j]=temp%10; } if(jinwei==1) { index++; arr[index]=1; } } for(int i=index;i>=0;i--) { cout<<arr[i]; } cout<<endl; return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。