题目:http://poj.org/problem?id=1995

题目解析:求(A1B1+A2B2+ ... +AHBH)mod M.

大水题。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
int n,mod,sum;
int main()
{
    int T,a[45010],b[45010];
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&mod,&n);
        int sum=0,t;
        for(int i=0; i<n; i++)
        {
            scanf("%d%d",&a[i],&b[i]);
            t=1;
            while(b[i])
            {
                if(b[i]&1)
                    t=(t*a[i])%mod;
                b[i]>>=1;
                a[i]=((a[i]%mod)*(a[i]%mod))%mod;
            }
            sum=(sum+t)%mod;
        }
        printf("%d\n",sum);
    }
    return 0;
}

 

相关文章:

  • 2019-07-18
  • 2021-06-27
  • 2022-12-23
  • 2021-08-06
  • 2021-08-06
  • 2021-08-06
  • 2021-08-06
  • 2022-12-23
猜你喜欢
  • 2021-10-02
  • 2021-09-03
  • 2021-08-12
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
相关资源
相似解决方案