5 条题解

  • 1
    @ 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);
    }
    
    • 1
      @ 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;}
      
      • -1
        @ 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
        @ 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;
          }
          
          • 1

          信息

          ID
          1562
          时间
          1000ms
          内存
          256MiB
          难度
          6
          标签
          递交数
          140
          已通过
          47
          上传者