No.2032 Let's Write Multiples!!
タグ : / 解いたユーザー数 33
作問者 :
とりゐ
Problem Statement
Suppose that all multiples of $K$ between $L$ and $R$, inclusive, are written out in decimal notation, each exactly $1$ time. Find the number of times the digit $C$ is written.
You are given $T$ test cases; solve each of them.
Constraints
- All input values are integers.
- $1 \leq T \leq 5 \times 10^4$
- $1 \leq L \leq R < 10^9$
- $1 \leq K < 10^9$
- $1 \leq C \leq 9$
Input
The input is given from standard input. Line $1$ is given in the following format.
$T$
Then, $T$ test cases follow, each given in the following format.
$L$ $R$ $K$ $C$
Output
Print $T$ lines. On line $i$ $(1 \leq i \leq T)$, print the answer to the $i$-th test case.
Print a newline at the end.
Sample
Sample 1
Input
6 30 39 3 3 1 99 100 1 123456789 234567890 2 3 999 9999999 999 9 3141592 653589793 238462 6 1 999999999 1 7
Output
5 0 40827156 7043 2704 900000000
$6$ cases are given.
For test case $1$, the multiples of $3$ between $30$ and $39$, inclusive, are $30, 33, 36, 39$. Thus, the digit $3$ is written $5$ times in total.
For test case $2$, there are no multiples of $100$ between $1$ and $99$, inclusive, so not even $1$ number is written. Thus, the digit $1$ is written $0$ times.
For test case $3$, when all multiples of $2$ between $123456789$ and $234567890$, inclusive, are written, the digit $3$ is written $40827156$ times.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。