luogu#P9897. [ICPC2018 Qingdao R] Function and Function
[ICPC2018 Qingdao R] Function and Function
题目描述
If we define $f(0) = 1, f(1) = 0, f(4) = 1, f(8) = 2, f(16) = 1, \dots$, do you know what function means?
Actually, calculates the total number of enclosed areas produced by each digit in . The following table shows the number of enclosed areas produced by each digit:
For example, , and .
We now define a recursive function by the following equations:
$$\begin{cases} g^0(x) = x \\ g^k(x) = f(g^{k-1}(x)) & \text{if } k \ge 1 \end{cases} $$For example, , and .
Given two integers and , please calculate the value of .
输入格式
There are multiple test cases. The first line of the input contains an integer (about ), indicating the number of test cases. For each test case:
The first and only line contains two integers and (). Positive integers are given without leading zeros, and zero is given with exactly one `0'.
输出格式
For each test case output one line containing one integer, indicating the value of .
题目大意
题目描述
如果我们定义 ,,,, …… 你知道函数 意味着什么吗?
其实, 计算的是 中每个数字所产生的封闭区域的总数。下表显示了每个数字产生的封闭区域数:
例如,,。
现在,我们用以下等式定义递归函数 :
$$\begin{cases} g^0(x) = x \\ g^k(x) = f(g^{k-1}(x)) & \text{if } k \ge 1 \end{cases} $$例如,,。
给定两个整数 和 ,请计算 的值。
输入格式
有多个测试用例。输入的第一行包含一个整数 (大约 ),表示测试用例的数量。 之后的每行包含两个整数 和 ()。正整数不带前导零,零则正好是一个 "0"。
输出格式
对每个测试用例输出一行,其中包含一个整数,表示 的值。
6
123456789 1
888888888 1
888888888 2
888888888 999999999
98640 12345
1000000000 0
5
18
2
0
0
1000000000