6 条题解

  • 1
    @ 2025-11-8 17:51:12

    什么叫作简单到傻子都会写的代码!

    #include<iostream>
    using namespace std;
    int main()
    {
    	long long x,n,cnt=1;
    	cin>>x>>n;
    	for(int i=1;i<=n;i++)
    	{
    		cnt*=x;	
    	}
    	cout<<cnt;	
    	return 0;
    } 
    
    
    • 0
      @ 2025-2-22 12:22:46

      快速幂

      #include<bits/stdc++.h>
      using namespace std;
      const int N=5e4+5,INF=0x3f3f3f3f;
      typedef long long LL;
      LL x,n;
      LL power(LL a,LL b){
      	LL ans=1;
      	while(b){
      		if(b&1)ans*=a;
      		b>>=1;
      		a*=a;
      	}
      	return ans;
      }
      int main()
      {
          cin>>x>>n;
          cout<<power(x,n);
      }
      
      • 0
        @ 2025-2-22 12:18:19

        最短

        #include<bits/stdc++.h>//写cmath浪费位置
        long long x,n,ans;int main(){std::cin>>x>>n;ans = pow(x,n);std::cout<<ans;}
        
        • 0
          @ 2023-3-19 18:21:19
          #include<iostream>
          #include<cmath>
          using namespace std;
          int main()
          {
              long long x,n,result;
              cin>>x>>n;
              result=pow(x,n);
              cout<<result;
              return 0;
          }
          
          • -1
            @ 2023-2-1 17:24:14
            #include<iostream>
            using namespace std;
            int main()
            {
            	long long a,b;
            	cin>>a>>b;
            	int q=a;
            	for(int i=1;i<b;i++)
            	{
            		a*=q;
            	}
            	cout<<a;
            }
            
            • -2
              @ 2023-5-29 19:23:56
              #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
              #define double long double
              using namespace std;
              const int N = 1e5 + 10;
              const int INF = 0x3f3f3f3f;
              int a, b;
              int power(int a, int b)
              {
              	int ans = 1; 
              	while(b)
              	{
              		if(b & 1)
              		{
              			ans = ans * a;
              		}
              		a = a * a;
              		b >>= 1;
              	}
              	return ans;
              }
              signed main()
              {
              	cin >> a >> b;
              	cout << power(a, b) << endl;
              	return 0;
              }
              

              当我写完题才发现要用递归...

            • 1

            信息

            ID
            1562
            时间
            1000ms
            内存
            256MiB
            难度
            5
            标签
            递交数
            168
            已通过
            61
            上传者