QOJ.ac

QOJ

حد الوقت: 5 s حد الذاكرة: 256 MB مجموع النقاط: 100 قابلة للهجوم ✓

#13049. 方程

الإحصائيات

对于给定的整数 $n$ 和 $m$,你需要找到方程 $n^x \equiv x \pmod{m}$ 的所有正整数解。

输入格式

输入仅包含一行,包含两个整数 $n$ 和 $m$ ($1 \le n \le m \le 1\,000\,000$)。

输出格式

输出仅包含一行,表示方程的所有正整数解。解集应表示为若干个不相交子集 $\{a_i k + b_i \mid k \ge 0\}$ ($a_i > 0, b_i > 0$) 的并集,其中每个子集都是一个无穷等差数列,且子集数量应尽可能少。每个子集需写成 “$\{ a_i k + b_i \}$” 的形式。使用字符 U(大写拉丁字母 u)作为并集运算符号。所有子集必须按照 $a_i$ 非递减的顺序打印,若 $a_i$ 相等,则按 $b_i$ 递增的顺序打印。如果子集数量超过 $50\,000$ 个,仅输出前 $50\,000$ 个,并在末尾加上文本 “ U ... (and S more)”,其中 $S$ 为未打印的子集数量。

题目保证对于任何合法的输入,结果均可以上述形式表示。

样例

样例输入 1

2 7

样例输出 1

{ 21k + 11 } U { 21k + 15 } U { 21k + 16 }

样例输入 2

3 7

样例输出 2

{ 42k + 2 } U ... (and 5 more)

说明

第二个测试用例的输出实际上应包含全部六个子集,此处为了演示超过 $50\,000$ 个子集的情况进行了缩减。

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.