#P10117. [LMXOI Round 1] Dreamer

[LMXOI Round 1] Dreamer

Background

Enhanced version link

This is a math problem, but it was made by LMX for HQZ.

Problem Description

Define the multiplicative function f(n)=(μId2)(n)f(n)=(\mu \ast\operatorname{Id_2})(n).

Given n,kn,k, you need to compute

$$\sum_{i_1\mid n}\sum_{i_2\mid i_1}\cdots\sum_{i_k\mid i_{k-1}}f(i_k)i_1i_k\mu^2\left(\dfrac{i_1}{i_k}\right)$$

Tips

μ\mu denotes the Möbius function.

For ff, we have $f(n)=\displaystyle \sum_{d\mid n}\mu(d)\left(\dfrac{n}{d}\right)^2$.

Input Format

This problem has multiple test cases. The first line contains a positive integer TT, the number of test cases.

Since nn is very large, we will give the standard prime factorization of n=i=1tpiαin=\displaystyle \prod_{i=1}^t p_i^{\alpha_i}.

For each query, we first give two integers k,mk,m.

The second line contains tt, and the next tt lines each contain two integers pi,αip_i,\alpha_i.

(It is guaranteed that pipi1p_i\ge p_{i-1} for i2i\ge 2, and αi1\alpha_i\ge 1.)

Output Format

For each query, output one line: the answer modulo mm.

5
3 998244353
3
3 2
5 1
7 1
4 1000000009
2
2 1
3 2
1 998244353
2
2 2
3 1
11451 191981012
11
2 1
3 1
5 1
7 1
11 1
13 1
17 1
19 1
23 1
29 1
31 1
514 520
2
2 10
3 10
189282114
124678
14965
82966193
260

Hint

For 100%100\% of the testdata, $T \le 20,n\le 10^{24},1\le k\le 10^6,m\le 1.14\times 10^9$.

Test Point ID nn kk TT Special Property
11 80\le 80 4\le 4 5\le 5 NN
22 106\le 10^6 10\le 10
33 1012\le 10^{12} 20\le 20 20\le 20
44 1018\le 10^{18} 1\le 1
55 103\le 10^3
66 105\le 10^5 AA
77 106\le 10^6 BB
88 1024\le 10^{24}
99 CC
102010\sim20 NN

Property AA: It is guaranteed that t10t\le 10.

Property BB: In the prime factorization i=1tpiαi\displaystyle\prod_{i=1}^t p_i^{\alpha_i} of nn, αi=1\alpha_i=1.

Property CC: mm is prime, and it is guaranteed that gcd(n,m)=1\gcd(n,m)=1.

Translated by ChatGPT 5