#P3216. [HNOI2011] 数学作业

[HNOI2011] 数学作业

Description

Xiao C excels in math, so the teacher assigned him a very difficult math homework problem:

Given positive integers n,mn,m, compute Concatenate(n)mod m\text{Concatenate}(n) \bmod \ m, where Concatenate(n)\text{Concatenate}(n) is the number obtained by concatenating all positive integers 1n1 \sim n in order.

For example, n=13n = 13, Concatenate(n)=12345678910111213\text{Concatenate}(n) = 12345678910111213. After thinking for a long time, Xiao C realized that this problem is impossible to work out by hand, so he asks you to write a program to solve it for him.

Input Format

One line with two positive integers n,mn,m.

Output Format

Output one integer on a single line representing the answer.

13 13
4

Hint

Constraints

For 30%30\% of the testdata, 1n1061\le n \le 10^6.
For 100%100\% of the testdata, 1n10181\le n \le 10^{18}, 1m1091\le m \le 10^9.

  • On 2023.4.20, one set of hack testdata was added.

Translated by ChatGPT 5