#P15556. [CCPC 2025 哈尔滨站] 函数求和

[CCPC 2025 哈尔滨站] 函数求和

Problem Description

Let the prime factorization of nn be:

$$n=\prod\limits_{i=1}^k p_i^{\alpha_i},\ p_1<p_2<\cdots<p_k$$

Now you are given a sequence rr of length mm with no repeated elements. Define f(n)f(n) as:

$$f(n)=\prod\limits_{i=1}^m p_{r_i}\times \alpha_{r_i}$$

If ri>kr_i>k, we treat pri×αri=1p_{r_i}\times \alpha_{r_i}=1.

You are given qq queries. In each query, an xx is given, and you need to compute the value of

$$\sum\limits_{i=1}^{\lfloor\frac{n}{x}\rfloor}f(ix)\bmod 2^{32}$$

for multiple queries.

To reduce output size, please output the XOR of all query answers. In particular, xx will be given in the form of its prime factorization.

Input Format

The first line contains three integers n,m,qn,m,q ($1 \le n \le 7 \times 10^8, 1 \le m \le 25, 1 \le q \le 5 \times 10^5$), representing the upper bound parameter, the length of the sequence rr, and the number of queries.

The second line contains mm integers r1,r2,,rmr_1,r_2,\ldots,r_m (1ri251 \le r_i \le 25, and all rir_i are distinct).

The next qq lines describe the queries. In the ii-th line, an integer LL is given first, indicating the number of prime factorization terms of xx. Then 2L2L integers P1,A1,P2,A2,,PL,ALP_1,A_1,P_2,A_2,\ldots,P_L,A_L are given (PiP_i are primes and are pairwise distinct), meaning

x=i=1LPiAix=\prod\limits_{i=1}^{L} P_{i}^{A_i}

It is guaranteed that 1xn1 \le x \le n and Ai1A_i\ge 1.

In particular, if L=0L=0, then x=1x=1.

Output Format

Output one line containing one integer, which is the XOR of the answers to all queries.

10 2 5
2 3
0
1 5 1
1 2 1
1 7 1
2 2 1 3 1
31

Hint

Translated by ChatGPT 5