12: Calculate the N power of 2, and 12 calculate the N power

Source: Internet
Author: User

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 }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.