A Prosperous Lot

发布时间: 2018年2月17日 15:24   时间限制: 1500ms   内存限制: 128M

Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.


Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony.

He would like to find how many integers $n$ between $l$ and $r$ such that there are exactly $k$ loops in the decimal representation of $n$.

A loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit $4$, two loops in $8$ and no loops in $5$. Refer to the figure below for all exact forms.


loops.png

The first line contains an integer $T$($T \le 10 ^ 5$) the number of testcases.
For each testcase, there is only one line, with three integers $l$, $r$, $k$.($1 \le l \le r \le 10^{18}$, $0 \le k \le 36$)

For each testcase, output the answer in one line.

复制
4
1 10 0
1 10 1
1 10 2
1 10 3
5
4
1
0

dp

Codeforces Round #462 (Div. 2)(改)