2017ccpc杭州站 Problem B. Master of Phi

公式,化简。

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=10000+10;
#define MOD 998244353
ll power(ll a, ll b)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
            res=(res*a)%MOD;
        }
        b>>=1;
        a=(a*a)%MOD;
    }
    return res%MOD;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        ll p[100], q[100];
        int m;
        scanf("%d",&m);
        for(int i=1;i<=m;i++)
        {
            scanf("%lld%lld",p+i,q+i);
        }
        ll ans=1;
        for(int i=1;i<=m;i++)
        {
            ll mu=power(p[i], q[i]-1);
            ans=(q[i]*p[i]%MOD+p[i]-q[i]+MOD)*mu%MOD*ans%MOD;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/jc12138/p/9591543.html