#P3216. Concatenation Modulo

    ID: 16473 Type: Default 1000ms 256MiB

Concatenation Modulo

Concatenation Modulo

Given two positive integers \(n\) and \(m\), compute \(\text{Concatenate}(n) \bmod m\) where \(\text{Concatenate}(n)\) is the number obtained by concatenating all positive integers from \(1\) to \(n\) in order.

For example, when \(n = 13\), we have
\[ \text{Concatenate}(13) = 12345678910111213 \] and the task is to compute
\[ 12345678910111213 \bmod m \]

Since \(\text{Concatenate}(n)\) can be extremely large, you are required to compute the result efficiently by performing the modulo operation during the concatenation process.

inputFormat

The input consists of a single line containing two space-separated positive integers \(n\) and \(m\).

outputFormat

Output a single integer which is the value of \(\text{Concatenate}(n) \bmod m\).

sample

13 7
2