2 条题解

  • 1
    @ 2023-4-26 15:39:44

    快速幂真的很快

    #include <bits/stdc++.h>
    #define int long long
    using namespace std;
    
    int quick_pow(int b,int p,int k)
    {
    	if(p == 0) return 1;
    	int ans = quick_pow(b,p/2,k);
    	ans = ans*ans%k;
    	if(p%2!=0) ans = ans*b%k;
    	return ans;
    }
    
    signed main()
    {
    	int b,p,k;
    	cin >> b >> p >> k;
    	printf("%lld",quick_pow(b,p,k));
    	return 0;
    }
    
    • 0
      @ 2023-5-5 21:18:47
      #include <bits/stdc++.h>
      using namespace std;
      int main(){
          int a,b,P;cin>>a>>b>>P;
          int res=1;
          while(b){
              if(b & 1) res=1ll*res*a%P;
              a=1ll*a*a%P;
              b>>=1;
          }
          cout<<res;
      }
      
      • 1

      「一本通 6.1 练习 1」A 的 B 次方

      信息

      ID
      673
      时间
      1000ms
      内存
      512MiB
      难度
      6
      标签
      递交数
      28
      已通过
      12
      上传者