hdu 6265 Master of Phi(数学)

数学题,主要是欧拉函数的简单应用和一个简单递推,一开始只是弄了个暴力,后来发现过不了,然后瞎逼搞了个递推一样的,就过了..每太清楚,晚上来补题解
其实只要拆分出互素因子之后发现是p-1/p就好,然后处理为1的情况,一开始我也是一个2^20,不过因为我是bitset遍历的,所以多20复杂度,过不了,如果dfs就可以过,这应该才是正解..现在这个做法感觉是阴差阳错..

#include <iostream>
#include <vector>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e6+17;
const int MOD = 998244353;
LL qm(LL a,LL b)
{
    LL res = 1;
    while(b)
    {
        if(b&1) res = a*res%MOD;
        b>>=1;
        a = a*a%MOD;
    }
    return res;
}
int main(int argc ,char const *argv[])
{
    #ifdef noob
    freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while(t--)
    {
        vector<pair<int,int > > vec;
        int n;
        cin>>n;
        vec.resize(n);
        for (int i = 0; i < n; ++i)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            vec[i] = {a,b};
        }
        LL ans = 1;
        for (int i = 0; i < n; ++i)
        {
            LL a = vec[i].first,b = vec[i].second;
            LL t1 = ans,t2 = ans;
            t1 = t1*qm(a,b)%MOD;
            t2 = (((t2*b%MOD)*qm(a,b-1))%MOD*(a-1))%MOD;
            ans = (t1+t2)%MOD;
        }
        cout<<ans<<endl;
    }
    return 0;   
}

猜你喜欢

转载自blog.csdn.net/m0_37802215/article/details/80136577