Master of Phi (欧拉函数 + 积性函数的性质 + 狄利克雷卷积)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Let_life_stop/article/details/84861470

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6265

题目大意:首先T是测试组数,n代表当前这个数的因子的种类,然后接下来的p和q,代表当前这个数的因子中含有p的q次方.然后让你求题目第一行给你的信息.

 首先理一下思路.

第一步,我们需要算题目中要求的公式(第一行),首先,他是一个积性函数,所以我们先将题目中的第一行的式子命名为F(n).对于F(n),我们可以分着求他的每一个因子的解,然后最终将这一写乘起来就可以了.

F(n) = F(p1^q1)*F(p2^q2)........*F(pn^qn).这是积性函数的一个性质.

(积性函数的介绍:https://baike.baidu.com/item/%E7%A7%AF%E6%80%A7%E5%87%BD%E6%95%B0/8354949?fr=aladdin)

第二步,我们开始化简这个式子.中间会运用到 欧拉函数的性质.

(欧拉函数的介绍:https://baike.baidu.com/item/%E6%AC%A7%E6%8B%89%E5%87%BD%E6%95%B0)

第一步,因为题目中给定的因数都是大于1的,所以需要对1单独讨论,然后到了第三行,利用欧拉函数的一个性质,

当f(x)中,x为 质数p的k次幂的时候,f(x)=(p-1)*p^(k-1).

然后其他顺着推下来就可以了.

最后就是将所有因子算出来的结果相乘就可以了(注意取模的位置).

AC代码:

#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<cstring>
#include<stdio.h>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn =100000+100;
# define ll long long
# define mod 998244353
struct node
{
    ll x,y;
} q[maxn];
ll quickpow(ll t1,ll t2)
{
    if(t2==0)return 1;
    t2--;
    ll ans=t1;
    while(t2)
    {
        if(t2&1)ans=ans*t1%mod;
        t1=t1*t1%mod;
        t2>>=1;
    }
    return ans%mod;
}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        for(int i=1; i<=n; i++)
        {
            cin>>q[i].x>>q[i].y;
        }
        ll ans=1;
        for(int i=1; i<=n; i++)
        {
            ll temp=quickpow(q[i].x,q[i].y-1);
            ans=ans*temp%mod*(q[i].x+(q[i].x-1)*q[i].y%mod+mod)%mod;
        }
        cout<<ans<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Let_life_stop/article/details/84861470