QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#5021. Six-variable Diophantine equation

Statistics

Given integers $N$ and $r$, find the number of ordered sextuplets $(a, b, c, a', b', c')$ such that the following congruence equations hold: $ab+a'b'\equiv bc+b'c'\equiv ca+c'a'\equiv r\pmod N$ where $a, b, c, a', b', c' \in \{0, 1, \dots, N-1\}$.

It is guaranteed that $\mu(N) \neq 0$, meaning that the exponent of every prime factor of $N$ is $1$.

Input

Two integers $N$ and $r$.

Output

A single integer representing the answer. The answer should be taken modulo $998\,244\,353$.

Examples

Input 1

2 0

Output 1

20

Input 2

15 1

Output 2

3472

Subtasks

For all test cases, it is guaranteed that $0 \le r < N \le 10^{18}$, $N \ge 2$, and $\mu(N) \neq 0$.

Subtask ID Score $N \leq$ Special Constraints
$1$ $7$ $50$ None
$2$ $8$ $500$
$3$ $15$ $10^7$
$4$ $20$ $10^{10}$ $r=0$
$5$ $20$ $r=1$
$6$ $10$ $10^{18}$ $N$ is prime
$7$ $20$ None

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.