#P5170. 【模板】类欧几里德算法

    ID: 5866 远端评测题 2000ms 125MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>Special Judge类欧几里得算法

【模板】类欧几里德算法

Problem Description

Given n,a,b,cn,\,a,\,b,\,c, compute respectively $\sum\limits_{i=0}^{n}\left\lfloor \frac{ai+b}{c} \right\rfloor$, $\sum\limits_{i=0}^{n}{\left\lfloor \frac{ai+b}{c} \right\rfloor}^2$, and $\sum\limits_{i=0}^{n} i \left\lfloor \frac{ai+b}{c} \right\rfloor$. Output each answer modulo 998244353998244353. There are multiple test cases.

Input Format

The first line contains the number of test cases tt.

The next tt lines each contain four integers, which are n, a, b, cn,\ a,\ b,\ c for that test case.

Output Format

For each test case, output one line with three integers, which are the three answers modulo 998244353998244353.

2
2 1 0 2
4 3 9 6
1 1 2
11 27 27

Hint

This problem uses Special Judge\mathrm{Special}\ \mathrm{Judge}.

If you answer all cases for the first query correctly, you can get 40%40\% of the total score. If you answer all cases for the second and third queries correctly, you can get an additional 30%30\% for each.

Test Point ID Special Property
11 n,a,b,c10n,\,a,\,b,\,c\leqslant10
232 \sim 3 n,a,b,c1000n,\,a,\,b,\,c\leqslant1000
44 n,a,b,c106n,\,a,\,b,\,c\leqslant10^6
55 t=1t=1
6106 \sim 10 None

For all test points, $1 \leqslant t \leqslant 10^5,\ 0 \leqslant n,\,a,\,b,\,c \leqslant 10^9,\ c \neq 0$.

Translated by ChatGPT 5