QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 128 MB 總分: 100

#16342. Math Homework

统计

Little C excels in mathematics, so his teacher gave him a very difficult math assignment: Given positive integers $N$ and $M$, calculate the value of $Concatenate(1 \dots N) \pmod M$, where $Concatenate(1 \dots N)$ is the number obtained by concatenating all positive integers $1, 2, \dots, N$ in order. For example, if $N = 13$, $Concatenate(1 \dots N) = 12345678910111213$.

Little C thought about it for a long time and finally realized that this is a problem that cannot be solved by hand, so he has to ask for your help, hoping that you can write a program to solve this problem for him.

Input

The input contains two positive integers $N$ and $M$ separated by a space on a single line. For 30% of the data, $1 \le N \le 1000000$. For 100% of the data, $1 \le N \le 10^{18}$ and $1 \le M \le 10^9$.

Output

Output a single non-negative integer representing the value of $Concatenate(1 \dots N) \pmod M$.

Examples

Input 1

13 13

Output 1

4

Input 2

12345678910 1000000000

Output 2

345678910

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.