#P3768. 简单的数学题

    ID: 2711 远端评测题 1000~4000ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学洛谷原创O2优化枚举,暴力莫比乌斯反演前缀和洛谷月赛

简单的数学题

Description

Since the problem setter is too lazy to write a background, let's keep the problem simple.

Given two integers pp and nn, compute:

$$\left(\sum_{i=1}^n\sum_{j=1}^n ij \gcd(i,j)\right) \bmod p$$

Here gcd(a,b)\gcd(a,b) denotes the greatest common divisor of aa and bb.

Input Format

A single line containing two integers pp and nn.

Output Format

Output a single integer on one line, the answer.

998244353 2000
883968974

Hint

For 20% of the testdata, n1000n \leq 1000.

For 30% of the testdata, n5000n \leq 5000.

For 60% of the testdata, n106n \leq 10^6, time limit 1 s.

For another 20% of the testdata, n109n \leq 10^9, time limit 3 s.

For the last 20% of the testdata, n1010n \leq 10^{10}, time limit 4 s.

For 100% of the testdata, 5×108p1.1×1095 \times 10^8 \leq p \leq 1.1 \times 10^9 and pp is prime.

Translated by ChatGPT 5