10 条题解

  • 2
    @ 2022-11-12 11:59:47
    #include <iostream>
    #include <math.h>
    using namespace std;
    int main()
    {
    	int a;
    	cin >> a;
    	a = pow(2,a);
    	cout << a;
    }
    
    • 1
      @ 2024-11-29 18:46:48
      #include<bits/stdc++.h>
      using namespace std;
      const int N=1e5+10;
      int main(){
      	int a,b=2;
      	cin>>a;
      	for(int i=1;i<=a;i++){
      		b=b*2;
      	}
      	cout<<b/2;
      	return 0;
      }
      
      • 1
        @ 2023-8-7 19:59:12
        #include<bits/stdc++.h>
        #include<cstring>
        #include<queue>
        #include<set>
        #include<stack>
        #include<vector>
        #include<map>
        #define ll long long
        using namespace std;
        const int N=1e5+10;
        const int M=2023;
        const int inf=0x3f3f3f3f;
        //快速幂
        ll n;
        ll power(ll a,ll b,ll p)
        {
        	ll ans=1,wq=a;
        	while(b)
        	{
        		if(b & 1)ans=ans*wq;
        		wq=wq*wq;
        		b>>=1;//删掉最后一位
        	}
        	return ans;
        }
        int main()
        {
        	cin>>n;
        	cout<<power(2,n,inf);
        	return 0;
        }
        

        快速幂

        • 1
          @ 2023-6-25 14:05:21
          #include <iostream>
          #include <stdio.h>
          #include <iomanip>
          #include <math.h>
          using namespace std;
          const int N = 1e6 + 10;
          const int INF = 0x3f3f3f3f;
          int main()
          {
          	int n;
          	cin >> n;
          	n = pow( 2 , n );
          	cout << n;
          	return 0;
          }
          
          • 0
            @ 2025-7-8 11:21:09

            #include

            #include

            using namespace std;

            int main()

            {

            int a;
            
            cin >> a;
            
            a = pow (2,a);
            
            cout << a;
            
            return 0;
            

            }

            • 0
              @ 2023-3-7 21:15:28

              P826 计算2的幂

              pow(x,y)意为 xyx^y

              注意,直接输出会WA,这是因为pow函数得数过长将转为科学计数法,将pow的得数存入变量即可,具体参见楼上、楼下 dalao 的代码,我个蒟蒻就不掺和了(就是不想写~嘿嘿)

            • 0
              @ 2022-11-6 13:15:07
              #include <bits/stdc++.h>
              
              using namespace std;
              
              int main()
              {
                  int n;
                  long long m = 1;
              
                  cin >> n;
              
                  for (int i = 1; i <= n; i++)
                  {
                      m *= 2;
                  }
              
                  cout << m;
              
                  return 0;
              }
              
              • 0
                @ 2022-10-24 18:00:21
                #include <iostream>
                #include <stack>
                #include <cmath>
                #include <vector>
                #include <string.h>
                #include <queue>
                #include <stdio.h>
                #include <iomanip>
                #include <cstdio>
                #include <algorithm>
                #define int long long
                using namespace std;
                const int N = 1e5 + 10;
                const int INF = 0x3f3f3f3f;
                signed main()
                {
                	int n;
                	cin >> n;
                	cout << (1 << n);
                	return 0;
                }
                

                可以试试位运算

                • -1
                  @ 2022-7-1 11:43:43
                  #include <stdio.h>
                  #include <iostream>
                  #include <math.h>
                  using namespace std;
                  int main()
                  {
                  	int a;
                  	cin >> a;
                  	a = pow(2,a);
                  	cout << a;
                  }
                  
                  • -4
                    @ 2022-1-17 22:53:36
                    #include <iostream>
                    using namespace std;
                    int main(){
                        int n,a=1;
                        scanf("%d",&n);
                        for(int i=0;i<n;i++)
                            a*=2;
                        printf("%d",a);
                        return 0;
                    }
                    
                    • 1

                    信息

                    ID
                    826
                    时间
                    1000ms
                    内存
                    128MiB
                    难度
                    4
                    标签
                    递交数
                    942
                    已通过
                    441
                    上传者