2 条题解

  • 0
    @ 2025-10-8 16:55:35
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    LL qpow(LL a, LL b, LL c)
    {
        LL ret = 1 % c; a = a % c;
        for (; b; b >>= 1, a = a * a % c) if (b & 1) ret = ret * a % c;
        return ret;
    }
    int main()
    {
        int T; scanf("%d", &T);
        while (T--)
        {
            int n; LL c; scanf("%lld%d", &c, &n);
            LL ans = 0;
            for (LL i = 1, a, b; i <= n; i++)
            {
                scanf("%lld%lld", &a, &b);
                ans = (ans + qpow(a, b, c)) % c;
            }
            printf("%lld\n", ans);
        }
        return 0;
    }
    
    • 0
      @ 2025-10-8 16:55:25
      #include<bits/stdc++.h>
      using namespace std;
      typedef long long LL;
      LL qpow(LL a,LL b,LL c)
      {
      	LL ret=1%c; a=a%c;
      	for(;b;b>>=1,a=a*a%c)if(b&1)ret=ret*a%c;
      	return ret;
      }
      int main()
      {
          int T;scanf("%d",&T);
          while(T--)
          {
              int n;LL c;scanf("%lld%d",&c,&n);
              LL ans=0;
              for(LL i=1,a,b;i<=n;i++)
              {
                  scanf("%lld%lld",&a,&b);
                  ans=(ans+qpow(a,b,c))%c;
              }
              printf("%lld\n",ans);
          }
          return 0;
      }
      • 1

      *【快速幂】幂函数序列求和[POJ1995]

      信息

      ID
      1114
      时间
      1000ms
      内存
      64MiB
      难度
      3
      标签
      递交数
      128
      已通过
      72
      上传者