#P17238. 『STA - R10』Petal Dance

    ID: 19728 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>数学数论O2优化前缀和Dirichlet 卷积

『STA - R10』Petal Dance

Problem Description

Aqua gives you two positive integers n,mn, m. For each integer 1≤k≤n1 \le k \le n, you need to compute

ak=∑i=1n∑j=1ngcd⁡(ij,k)a_k=\sum_{i=1}^n\sum_{j=1}^n\gcd(ij,k)

The answer should be taken modulo mm.

Input Format

One line contains two positive integers n,mn, m.

Output Format

Since the output would be too large, you only need to output the value of $\displaystyle\bigoplus_{k = 1}^n \left( k \cdot (a_k\bmod m) \right)$ (note where the modulo is applied).

10 998244353
7854
1000000 998244353
666900907572623

Hint

Explanation for Sample 1: $\{a_k\} = \{100, 175, 202, 265, 244, 347, 214, 369, 340, 427\}$.

This problem uses bundled testdata.

Subtask Score Special Property
1 5 n≤500n \le 500
2 m=2m = 2
3 15 n≤5×103n \le 5\times 10^3
4 n≤105n \le 10^5
5 20 n≤106n \le 10^6
6 40 None

Constraints for all testdata: 1≤n≤5×1061\le n\le 5\times 10^6, 1≤m≤1091\le m \le 10^9.

Translated by ChatGPT 5