P17238 『STA - R10』Petal Dance

Description

Aqua gives you two positive integers $n, m$. For each integer $1 \le k \le n$, you need to compute $$a_k=\sum_{i=1}^n\sum_{j=1}^n\gcd(ij,k)$$ The answer should be taken modulo $m$.

Input Format

One line contains two positive integers $n, 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).

Explanation/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 \le 500$ | | 2 | 5 | $m = 2$ | | 3 | 15 | $n \le 5\times 10^3$ | | 4 | 15 | $n \le 10^5$ | | 5 | 20 | $n \le 10^6$ | | 6 | 40 | None | Constraints for all testdata: $1\le n\le 5\times 10^6$, $1\le m \le 10^9$. Translated by ChatGPT 5