#P17255. [Aboi 2077] 全部夢だった!

    ID: 19729 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>数论O2优化群论线性代数2077杜教筛亚线性快速求和算法

[Aboi 2077] 全部夢だった!

Background

Become a star floating in the moonlit night.

:::info[Noun Explanations] Define three types of congruence subgroups of SL2(Z)\text{SL}_2(\mathbb Z) modulo NN: Γ0,Γ1,Γ\Gamma_0,\Gamma_1,\Gamma:

$$\begin{aligned} \Gamma_0(N)&=\left\{\begin{bmatrix}a&b\\c&d\end{bmatrix}\in\text{SL}_2(\mathbb Z)\mathrel{\Bigg|}\begin{bmatrix}a&b\\c&d\end{bmatrix}\equiv\begin{bmatrix}*&*\\0&*\end{bmatrix}\pmod N\right\}\\ \Gamma_1(N)&=\left\{\begin{bmatrix}a&b\\c&d\end{bmatrix}\in\text{SL}_2(\mathbb Z)\mathrel{\Bigg|}\begin{bmatrix}a&b\\c&d\end{bmatrix}\equiv\begin{bmatrix}1&*\\0&1\end{bmatrix}\pmod N\right\}\\ \Gamma(N)&=\left\{\begin{bmatrix}a&b\\c&d\end{bmatrix}\in\text{SL}_2(\mathbb Z)\mathrel{\Bigg|}\begin{bmatrix}a&b\\c&d\end{bmatrix}\equiv\begin{bmatrix}1&0\\0&1\end{bmatrix}\pmod N\right\} \end{aligned}$$

Here, * means there is no restriction.

Define the cusps of a congruence subgroup Γ\Gamma as the equivalence classes of Q{}\mathbb Q\cup\{\infty\} under the action of Γ\Gamma. Here, for $\gamma=\begin{bmatrix}a&b\\c&d\end{bmatrix}\in\Gamma$, the action is defined as γ(s)=as+bcs+d\gamma(s)=\dfrac{as+b}{cs+d}. In particular, γ()=ac\gamma(\infty)=\dfrac ac; if the denominator is 00, then the value is \infty.

Let ε(Γ)\varepsilon_\infty(\Gamma) be the number of cusps of the congruence subgroup Γ\Gamma. :::

Problem Description

Given a positive integer NN, for a given G{Γ0,Γ1,Γ}G\in\{\Gamma_0,\Gamma_1,\Gamma\}, compute n=1Nε(G(n))\displaystyle\sum_{n=1}^N\varepsilon_\infty(G(n)), modulo 998244353998244353.

Input Format

A single line with two integers N,oN,o. Here o=0,1,2o=0,1,2 correspond to G=Γ0,Γ1,ΓG=\Gamma_0,\Gamma_1,\Gamma, respectively.

Output Format

Output one integer, the value of the answer modulo 998244353998244353.

10 0
28
10 1
44
10 2
158

Hint

Subtask 1: o=0o=0, N1015N\le10^{15}.
Subtask 2: o=1o=1, N1011N\le10^{11}.
Subtask 3: o=2o=2, N1011N\le10^{11}.

Translated by ChatGPT 5