#P6055. [RC-02] GCD

[RC-02] GCD

Description

Given NN, compute:

$$\sum_{i=1}^N\sum_{j=1}^N\sum_{p=1}^{\lfloor\frac{N}{j}\rfloor}\sum_{q=1}^{\lfloor\frac{N}{j}\rfloor}[\gcd(i,j)=1][\gcd(p,q)=1]$$

Output the answer modulo 998244353998244353.

[][] is a conditional expression. When the statement inside the brackets is true, its value is 11, otherwise it is 00.

Input Format

A single line containing one integer NN.

Output Format

Output one integer, the required answer modulo 998244353998244353.

50

104527

200

6664993

500000

835964450

10000000

503290049
100000000
712748411

1000000000
845640070

Hint

For all data, it is guaranteed that 1N2×1091\le N\le 2\times10^9. The time limit for all test points is 1s1\text{s}, and the memory limit is 500MB500\text{MB}.

Test Point ID NN
11 100\le 100
22 400\le 400
3,4,5,63,4,5,6 106\le10^6
7,87,8 2×107\le 2\times10^7
99 2×108\le 2\times10^8
1010 2×109\le 2\times10^9

This problem could actually have been made into multiple test cases in one input. But the kind problem setter decided to use only one test case, to give you more chances to get partial points.

The idea came from @Fee_cle6418. The statement, official solution, and testdata come from @FangZeLi.

Translated by ChatGPT 5