QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 512 MB Puntuación total: 100

#16465. Flip

Estadísticas

Yuki is a mathematician who loves studying numbers!

Yuki defines the reversal $R_k(n)$ of a positive integer $n$ in base $k$ as the number obtained by writing the digits of $n$ in base $k$ in reverse order and removing any leading zeros.

For example, $R_{10}(521)=125$ and $R_2(10110)=1101$.

Now, Yuki has a positive integer $k$ in base 10 and a positive integer $n$ in base $k$. She wants you to find how many positive integers $x$ in base $k$ such that $x \le n$ satisfy the condition that $R_k(x)$ is a multiple of $x$. You need to output the answer in base 10, modulo $998244353$.

Input

The first line contains a positive integer $k$ in base 10.

The second line contains a positive integer $n$ in base $k$ (where $10, 11, 12, 13, 14, 15$ are represented by the uppercase letters $\texttt A, \texttt B, \texttt C, \texttt D, \texttt E, \texttt F$ respectively).

Output

Output a single integer in base 10, representing the number of positive integers $x$ that satisfy the condition, modulo $998244353$.

Examples

Input 1

10
9999

Output 1

200

Note 1

$R_{10}(1089)=9801=9\times1089$ and $R_{10}(2178)=8712=4\times2178$, so both these numbers satisfy the condition. The remaining numbers that satisfy the condition are those where $R_{10}(x)=x$. There are $90$ such four-digit numbers, $90$ three-digit numbers, $9$ two-digit numbers, and $9$ one-digit numbers. In total, there are $90+90+9+9+2=200$ such numbers.

Input 2

See the files $\textit{reverse/reverse2.in}$ and $\textit{reverse/reverse2.ans}$ in the provided materials.

This sample case satisfies the constraints of test case 4.

Input 3

See the files $\textit{reverse/reverse3.in}$ and $\textit{reverse/reverse3.ans}$ in the provided materials.

This sample case satisfies the constraints of test case 7.

Input 4

See the files $\textit{reverse/reverse4.in}$ and $\textit{reverse/reverse4.ans}$ in the provided materials.

This sample case satisfies the constraints of test case 10.

Input 5

See the files $\textit{reverse/reverse5.in}$ and $\textit{reverse/reverse5.ans}$ in the provided materials.

This sample case satisfies the constraints of test case 14.

Input 6

See the files $\textit{reverse/reverse6.in}$ and $\textit{reverse/reverse6.ans}$ in the provided materials.

This sample case satisfies the constraints of test case 18.

Input 7

See the files $\textit{reverse/reverse7.in}$ and $\textit{reverse/reverse7.ans}$ in the provided materials.

This sample case satisfies the constraints of test case 25.

Constraints

For all test cases, it is guaranteed that:

  • $2 \le k \le 16$;
  • $1 \le n \lt k^{10^5}$.
Test Case ID $n <$ $k$
$1\sim 3$ $10^6$ $\le 16$
$4\sim 6$ $k^{10}$ $\le 16$
$7\sim 9$ $k^{10^5}$ $= 2$
$10\sim 13$ $k^{10^5}$ $= 3$
$14\sim 17$ $k^{10^5}$ $= 4$
$18\sim 21$ $k^{10^5}$ $= 5$
$22\sim 25$ $k^{10^5}$ $\le 16$

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.