hdu 6265 Master of Phi 积性函数

推式子

a n s = d n ϕ ( d ) n d \begin{aligned} ans= \sum_{d \mid n}\phi(d)\frac{n}{d} \end{aligned}

题目给了唯一分解: n = p 1 q 1 p m q m n=p_1^{q_1}*……*p_m^{q_m} ,所以我们枚举 p i q i p_i^{q_i}

a n s = n p q n i = 0 q ϕ ( p i ) p i = n p q n ( 1 + i = 1 q ϕ ( p i ) p i ) = n p q n ( 1 + i = 1 q p i p i 1 p i ) = n p q n ( 1 + i = 1 q p 1 p ) \begin{aligned} ans= n\prod_{p^{q} \mid n}\sum_{i=0}^{q}\frac{\phi(p^{i})}{p^{i}}= n\prod_{p^{q} \mid n}(1+\sum_{i=1}^{q}\frac{\phi(p^{i})}{p^{i}})= n\prod_{p^{q} \mid n}(1+\sum_{i=1}^{q}\frac{p^{i}-p^{i-1}}{p^{i}})= n\prod_{p^{q} \mid n}(1+\sum_{i=1}^{q}\frac{p-1}{p}) \end{aligned}

最终:

a n s = p q n ( p q 1 ( p + q p q ) ) ans= \prod_{p^{q} \mid n}(p^{q-1}(p+q*p-q))

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T>
void out(T x) { cout << x << endl; }
ll fast_pow(ll a, ll b, ll p) {ll c = 1; while(b) { if(b & 1) c = c * a % p; a = a * a % p; b >>= 1;} return c;}
ll exgcd(ll a, ll b, ll &x, ll &y) { if(!b) {x = 1; y = 0; return a; } ll gcd = exgcd(b, a % b, y, x); y-= a / b * x; return gcd; }
const ll mod = 998244353;
int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while(t --)
    {
        int m;
        cin >> m;
        ll ans = 1;
        for(int i = 0; i < m; i ++)
        {
            ll p, q;
            cin >> p >> q;
            ll dd = fast_pow(p, q - 1, mod);
            ans = (ans * dd % mod * (p * (q + 1) % mod - q + mod) % mod) % mod;
        }
        cout << ans << endl;
    }
    //system("pause");
}
原创文章 83 获赞 6 访问量 2754

猜你喜欢

转载自blog.csdn.net/qq_43101466/article/details/102691533
phi