QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#7996. 报数 IV

统计

题目背景

这是小 R 和小 Z 第四次玩报数游戏了,因此他们决定不再编冗长的题面了。你只需要知道,他们又编了一个奇怪的报数规则,然后想算一下有哪些数字可以报出来。

题目描述

对于任意正整数 $n$,定义函数 $f(n)$ 为 $n$ 在十进制下各个数位之和,如 $f(114514)=1+1+4+5+1+4=16$。显然 $f(n)$ 也是正整数,因此可以嵌套地考虑 $f(f(n)),f(f(f(n)))$ 等等。进而对于正整数 $n,k$ 可以定义 $g(n,k)=f(f(...f(n)))$(共有 $k$ 层 $f$)。

为了让报数游戏不再每局都是一模一样的,小 R 和小 Z 决定为每局游戏设置两个正整数 $k,m$,然后规定:在这一局游戏中,所有满足 $g(n,k)=m$ 的正整数 $n$ 都是不能报出的。

因为两人都是游戏高手,为防止游戏无限进行下去,每局游戏中还给出了一个正整数 $N$ 表示报数的上界。两人想知道:在不超过 $N$ 的正整数中,有多少是按这个规则不能报出的。

输入格式

从标准输入读入数据。

第一行:一个正整数 $T$,表示小 R 和小 Z 进行的游戏轮数,保证 $1 \le T \le 5$。

接下来 $T$ 行,每行 $3$ 个正整数 $N,k,m$,描述一局游戏,含义如上文所述。保证 $1 \le N \le 10^{1000}, 1 \le k,m \le 10^9$。

输出格式

输出到标准输出。

输出 $T$ 行,每行一个整数,表示这局游戏中不能报出的数的个数,对 $10^9+7$ 取模。

样例

输入

2
114 1 5
514 2 10

输出

8
10

解释

第一局游戏中,不能报出的数有 $5,14,23,32,41,50,104,113$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.