

Time Limit: 3 sec / Memory Limit: 1024 MB
配点: 600 点
問題文
長さ L の等差数列 s_0, s_1, s_2, ... , s_{L-1} があります。
この等差数列の初項は A、公差は B です。つまり、s_i = A + B \times i が成り立ちます。
この数列の各項を、先頭に 0 の無い十進法表記に直し、順につなげて読んでできる整数を考えます。たとえば、数列 3, 7, 11, 15, 19 をつなげて読んでできる整数は 37111519 となります。この整数を M で割ったあまりはいくらでしょうか。
制約
- 入力はすべて整数である
- 1 \leq L, A, B < 10^{18}
- 2 \leq M \leq 10^9
- 等差数列の要素は全て 10^{18} 未満
入力
入力は以下の形式で標準入力から与えられます。
L A B M
出力
数列の各項をつなげて読んだ整数を M で割ったあまりを出力してください。
入力例 1
5 3 4 10007
出力例 1
5563
考える等差数列は 3, 7, 11, 15, 19 なので,37111519 を 10007 で割ったあまりである 5563 が答えです.
入力例 2
4 8 1 1000000
出力例 2
891011
入力例 3
107 10000000000007 1000000000000007 998244353
出力例 3
39122908
Score : 600 points
Problem Statement
There is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}.
The initial term is A, and the common difference is B. That is, s_i = A + B \times i holds.
Consider the integer obtained by concatenating the terms written in base ten without leading zeros. For example, the sequence 3, 7, 11, 15, 19 would be concatenated into 37111519. What is the remainder when that integer is divided by M?
Constraints
- All values in input are integers.
- 1 \leq L, A, B < 10^{18}
- 2 \leq M \leq 10^9
- All terms in the arithmetic progression are less than 10^{18}.
Input
Input is given from Standard Input in the following format:
L A B M
Output
Print the remainder when the integer obtained by concatenating the terms is divided by M.
Sample Input 1
5 3 4 10007
Sample Output 1
5563
Our arithmetic progression is 3, 7, 11, 15, 19, so the answer is 37111519 mod 10007, that is, 5563.
Sample Input 2
4 8 1 1000000
Sample Output 2
891011
Sample Input 3
107 10000000000007 1000000000000007 998244353
Sample Output 3
39122908