hdu 6265 Master of Phi 数论

问题 B: Master of Phi

时间限制: 1 Sec  内存限制: 128 MB
提交: 110  解决: 55
[提交] [状态] [命题人:admin]

题目描述

You are given an integer n. Please output the answer of   modulo 998244353. n is represented in the form of factorization.

φ(n) is Euler’s totient function, and it is defi ned more formally as the number of integers k in the interval 1≤k≤n for which the greatest common divisor gcd(n,k) is equal to 1.
For example, the totatives of n = 9 are the six numbers 1, 2, 4, 5, 7 and 8. They are all co-prime to 9, but the other three numbers in this interval, 3, 6, and 9 are not, because gcd(9,3) = gcd(9,6) = 3 and gcd(9,9) = 9. Therefore, φ(9) = 6. As another example, φ(1) = 1 since for n = 1 the only integer in the interval from 1 to n is 1 itself, and gcd(1,1) = 1.
And there are several formulas for computing φ(n), for example, Euler’s product formula states like:

where the product is all the distinct prime numbers (p in the formula) dividing n.

 

输入

The fi rst line contains an integer T (1≤T≤20) representing the number of test cases.
For each test case, the fi rst line contains an integer m(1≤m≤20) is the number of prime factors.
The following m lines each contains two integers pi and qi (2≤pi≤108 , 1≤qi≤108 ) describing that n contains the factor piqi , in other words, . It is guaranteed that all pi are prime numbers and diff erent from each other.

 

输出

For each test case, print the the answer modulo 998244353 in one line.

 

样例输入

复制样例数据

2
2
2 1
3 1
2
2 2
3 2

样例输出

15
168

 

提示

For first test case, n = 21*31= 6, and the answer is (φ(1)*n/1+φ(2)*n/2+φ(3)*n/3+φ(6)*n/6) mod 998244353 = (6 + 3 + 4 + 2) mod 998244353 = 15.

对数论大佬当然是个简单推导题,但是对数论白痴来说,emmm

式子是狄利克雷卷积公式,公式推导话,看这篇博客

补充一下 φ( p^i ) = p^i * (p-1) 

欧拉函数表示与p^i 互质的数的个数,因为p是质数,p没有因数,那么不互质的数就是p的倍数,即 p^i-1

那么显然互质的个数就是 p^i - p^i-1 = p^i * (p-1)

代码:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 2e5 + 100;
const int inf = 1e9;
const int mod = 998244353;

ll qpow(ll a, ll b) {
    ll ret = 1;
    while (b) {
        if (b & 1) ret = ret * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ret % mod;
}

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        ll q, p;
        scanf("%d", &n);
        ll ans = 1;
        while (n--) {
            scanf("%lld%lld", &p, &q);
            ll temp = 1;
            temp = (temp * p % mod + ((p - 1) * q) % mod) % mod;
            temp = (temp * qpow(p, q - 1) % mod) % mod;
            ans = (ans * temp) % mod;
        }
        printf("%lld\n", ans % mod);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值