QOJ.ac

QOJ

Limite de temps : 2.5 s Limite de mémoire : 256 MB Points totaux : 100 Hackable ✓

#8143. 方程

Statistiques

设 $f(a, b, m)$ 为同余方程的最小非负整数解:

$$ax \equiv b \pmod{m}$$

若该方程无解,则 $f(a, b, m) = 0$。

给定 $n, a, b$,计算 $\sum_{i=1}^{n} f(a, b, i) \pmod{998244353}$。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 5$),表示测试用例的数量。

接下来 $T$ 行,每行包含三个正整数 $n, a, b$ ($1 \le n \le 10^{18}, 1 \le a, b \le 10^6$)。

输出格式

输出 $T$ 行。第 $i$ 行包含第 $i$ 个测试用例的答案。

样例

样例输入 1

5
5 4 3
5 3 4
10 5 8
10 8 5
100 79 97

样例输出 1

2
3
15
10
2519

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.