3 条题解

  • 1
    @ 2025-9-18 20:37:51
    #include<queue>
    #include<math.h>
    #include<stdio.h>
    #include<iostream>
    #include<vector>
    #include<iomanip>
    #include<string.h>
    #include<algorithm>
    #include<cmath>
    #include<cstdio>
    #include<utility>
    #include<cstring>
    #include<stack>
    #include<fstream>
    #include<string>
    using namespace std;
    #define LL long long
    const int N = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    typedef long long ll;
    ll a , b;
    ll pow()
    {
    	ll ans = 1;
    	while ( b )
    	{
    		if ( b % 2 == 1 )
    		{
    			ans = ans * a;
    		}
    		b /= 2;
    		a = a * a;
    	}
    	return ans;
    }
    int main()
    {
    	cin >> a >> b;
    	cout << pow();
    	return 0;
    }
    
    • 0
      @ 2023-5-13 11:42:48

      #include<bits/stdc++.h> using namespace std; int fast(int a, int b) { int ans; if(b%20){ a*=a; b/=2; ans=pow(a,b); } else if(b%21){ b-=1; ans=a*pow(a,b); } return ans; } int main(){ int a,b,m; cin>>a>>b>>m; cout<<fast(a,b)%m; }

      • 0
        @ 2023-3-31 19:42:35
        #include<iostream>
        using namespace std;
        typedef long long ll;//将long long改名成ll
        ll a,b;
        ll pow(){
        ll ans=1;
        	while(b){
        		if(b%2==1)ans=ans*a;//次数为单数时乘1次
        		b/=2;//次数除以2
        		a=a*a;//a自乘
        	}
        	return ans;
        }
        int main(){
        	cin>>a>>b;
        	cout<<pow();
        	return 0;
        }
        
        • 1

        信息

        ID
        1661
        时间
        1000ms
        内存
        256MiB
        难度
        4
        标签
        递交数
        32
        已通过
        17
        上传者