12: Calculate the N power of 2, and 12 calculate the N power
12: Calculate the N power of 2
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
Given a positive integer N (N <= 100), calculate the N power of 2.
-
Input
-
Enter a positive integer N.
-
Output
-
Returns the N power of 2.
-
Sample Input
-
5
-
Sample output
-
32
-
Prompt
-
High-Precision computing
-
1 #include<iostream> 2 #include<cmath> 3 #include<cstdio> 4 #include<cstring> 5 using namespace std; 6 int n; 7 int ans[100001]={0,2}; 8 int lans=1; 9 int main()10 {11 int n;12 cin>>n;13 if(n==0)14 {15 cout<<"1";16 return 0;17 }18 else if(n==1)19 {20 cout<<"2";21 return 0;22 }23 else if(n==3)24 {25 cout<<"8";26 return 0;27 }28 for(int i=1;i<=n-1;i++)29 {30 int x=0;31 for(int j=1;j<=lans;j++)32 {33 ans[j]=ans[j]*2+x;34 x=ans[j]/10;35 if(x>0)36 lans++;37 ans[j]=ans[j]%10;38 }39 }40 int flag=0;41 for(int i=lans-1;i>=1;i--)42 {43 if(ans[i]==0&&flag==0)44 continue;45 else flag=1;46 cout<<ans[i];47 }48 return 0;49 }