HDU-6265 Master of Phi (数论)

博客介绍了HDU 6265 Master of Phi问题,涉及数论中的Euler's totient函数和狄利克雷卷积。题目要求求解n的所有因子d的φ(d)×dn之和模998244353。解题关键在于理解积性函数的性质,通过将n表示为质因数的乘积,利用Euler's product formula简化计算,最后对每一对质因数pi、qi分别计算并累乘得到答案。

2017 杭州CCPC HDU 6265 Master of Phi

You are given an integer n. Please output the answer of ∑d∣nφ(d)×nd  modulo  998244353.\sum\nolimits_{d|n}φ(d)×\frac{n}{d}\;modulo\;998244353.dnφ(d)×dnmodulo998244353. n is represented in the form of factorization.
φ(n) is Euler’s totient function, and it is defined 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:
ϕ(n)=n∏p∣n(1−1p), \phi(n) = n\prod\nolimits_{p|n}\left(1 - \frac{1}{p}\right), ϕ(n)=npn(1p1),
where the product is all the distinct prime numbers (p in the formula) dividing n.

Input

The first line contains an integer T (1 ≤ T ≤ 20) representing the number of test cases.
For each test case, the first line contains an integer m (1 ≤ m ≤ 20) is the number of prime factors.
The following m lines each contains two integers pip_ipi and qiq_iqi (2 ≤ pip_ipi ≤ 108, 1 ≤ qiq_iqi ≤ 108) describing that n contains the factor piqip_i^{qi}piqi, in other words, n=∏i=1mpiqi.n=∏^m_{i=1}p_i^{q_i}.n=i=1mpiqi. It is guaranteed that all pi are primenumbers and different from each other.

Output

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

standard input standard output
2
2
2 1
3 1
2
2 2
3 2
15
168

Explanation

For first test case, n = 212^121313^131 = 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.

题意

首先给你一个数m,接着是m对数pip_ipi,qiq_iqi</

### 关于HDU - 6609 的题目解析 由于当前未提供具体关于 HDU - 6609 题目的详细描述,以下是基于一般算法竞赛题型可能涉及的内容进行推测和解答。 #### 可能的题目背景 假设该题目属于动态规划类问题(类似于多重背包问题),其核心在于优化资源分配或路径选择。此类问题通常会给出一组物品及其属性(如重量、价值等)以及约束条件(如容量限制)。目标是最优地选取某些物品使得满足特定的目标函数[^2]。 #### 动态转移方程设计 如果此题确实是一个变种的背包问题,则可以采用如下状态定义方法: 设 `dp[i][j]` 表示前 i 种物品,在某种条件下达到 j 值时的最大收益或者最小代价。对于每一种新加入考虑范围内的物体 k ,更新规则可能是这样的形式: ```python for i in range(n): for s in range(V, w[k]-1, -1): dp[s] = max(dp[s], dp[s-w[k]] + v[k]) ``` 这里需要注意边界情况处理以及初始化设置合理值来保证计算准确性。 另外还有一种可能性就是它涉及到组合数学方面知识或者是图论最短路等相关知识点。如果是后者的话那么就需要构建相应的邻接表表示图形结构并通过Dijkstra/Bellman-Ford/Floyd-Warshall等经典算法求解两点间距离等问题了[^4]。 最后按照输出格式要求打印结果字符串"Case #X: Y"[^3]。 #### 示例代码片段 下面展示了一个简单的伪代码框架用于解决上述提到类型的DP问题: ```python def solve(): t=int(input()) res=[] cas=1 while(t>0): n,k=list(map(int,input().split())) # Initialize your data structures here ans=find_min_unhappiness() # Implement function find_min_unhappiness() res.append(f'Case #{cas}: {round(ans)}') cas+=1 t-=1 print("\n".join(res)) solve() ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值