2 条题解

  • 0
    @ 2025-10-8 16:59:25
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    typedef __int128 i128;
    const LL P = 1e9;
    LL qpow(i128 a, i128 b)
    {
        i128 ret = 1ll;
        for (; b; b >>= 1, a = a * a)
        {
            if (b & 1) ret = ret * a;
            if (ret > P) return -1;
        }
        return LL(ret);
    }
    int main()
    {
        LL a, b; scanf("%lld%lld", &a, &b);
        printf("%lld\n", qpow(a, b)); 
        return 0;
    }
    
    • 0
      @ 2025-10-8 16:59:20
      #include<bits/stdc++.h>
      using namespace std;
      typedef long long LL;
      typedef __int128 i128;
      const LL P=1e9;
      LL qpow(i128 a,i128 b)
      {
          i128 ret=1ll;
          for(;b;b>>=1,a=a*a)
          {
              if(b&1)ret=ret*a;
              if(ret>P) return -1;
          }
          return LL(ret);
      }
      int main()
      {
          LL a,b;scanf("%lld%lld",&a,&b);
          printf("%lld\n",qpow(a,b)); 
          return 0;
      }
      • 1

      信息

      ID
      1978
      时间
      100ms
      内存
      128MiB
      难度
      7
      标签
      递交数
      316
      已通过
      84
      上传者