#P4113. Zju2599 Graduated Lexicographical Ordering

Zju2599 Graduated Lexicographical Ordering

考虑从 1 到 n 的整数。我们将一个整数各位数字之和称为它的“权重”。记数字 x 的权重为 w(x)。

现在,让我们使用所谓的“渐进字典序排序”(或简称 grlex 排序)来对这些数字进行排序。考虑两个整数 a 和 b。如果 w(a) < w(b),那么在 grlex 排序中 a 排在 b 之前。如果 w(a) = w(b),那么当且仅当 a 的十进制表示在字典序上小于 b 的十进制表示时,a 才排在 b 之前。

让我们看一些例子:

  • 120<grlex4120 <_{\text{grlex}} 4,因为 w(120)=1+2+0=3<4=w(4)w(120) = 1 + 2 + 0 = 3 < 4 = w(4)
  • 555<grlex78555 <_{\text{grlex}} 78,因为 w(555)=15=w(78)w(555) = 15 = w(78),并且 "555" 在字典序上小于 "78"。
  • 20<grlex20020 <_{\text{grlex}} 200,因为 w(20)=2=w(200)w(20) = 2 = w(200),并且 "20" 在字典序上小于 "200"。

给定 n 和某个整数 k,找出数字 k 在从 1 到 n 的整数的 grlex 排序中的位置,以及该排序中的第 k 个数字。


输入规范:

输入文件包含多行,每行包含两个整数 n 和 k (1kn10181 \le k \le n \le 10^{18})。

以一行 n = k = 0 结束输入。


输出规范:

对于输入中的每一行,在输出文件中输出一行。首先输出数字 k 在从 1 到 n 的整数的 grlex 排序中的位置,然后输出该排序中占据第 k 个位置的整数。


## 题目描述
Consider integer numbers from 1 to n. Let us call the sum of digits of an integer number its weight. Denote the weight of the number x as w(x). Now let us order the numbers using so called graduated lexicographical ordering, or shorter grlex ordering. Consider two integer numbers a and b. If w(a) < w(b) then a goes before b in grlex ordering. If w(a) = w(b) then a goes before b in grlex ordering if and only if the decimal representation of a is lexicographically smaller than the decimal representation of b. Let us consider some examples. 120 < grlex4 since w(120) = 1 + 2 + 0 = 3 < 4 = w(4). 555 < grlex78 since w(555) = 15 = w(78) and "555" is lexicographicaly smaller than "78". 20 < grlex200 since w(20) = 2 = w(200) and "20" is lexicographicaly smaller than "200". Given n and some integer number k, find the position of the number k in grlex ordering of integer numbers from 1 to n, and the k-th number in this ordering. 
考虑所有从1到n的整数。我们设一个整数 x 的十进制各位数字之和为 w(x)。 
让我们重新将整数排序:对于整数a 和整数b,如果w(a)<w(b),则a 在 b之前。如果
w(a)=w(b),那么a 在b之前当且仅当a 的十进制表示在字典序中小于 b 的十进制表示。例
如: 
120 < grlex4 因为  w(120) = 1 + 2 + 0 = 3 < 4 = w(4)。 
555 < grlex78 因为  w(555) = 15 = w(78) 并且  "555"  的字典序小于  "78"。 
20 < grlex200 因为  w(20) = 2 = w(200) 并且  "20"  的字典序小于  "200"。 
给定整数n和k,你需要求出1-n中的数按照上述方法排序后,k是第几个数,以及第 k
个数是多少。 
输入:包含多组数据,每组数据包含两个整数 n和 k。输入的最后一行是 n=k=0。 
输出:对于每组数据,输出一行两个整数,分别表示k在 1-n中的编号,以及第 k个数
是多少。 
数据规模:1 ≤ k ≤ n ≤ 10^18
。 
## 输入格式
There are several lines in the input file, and each line stands two integers n and k (1 <= k <= n <= 10^18). 
## 输出格式
For each line in the input, output one line in the output file. First print the position of the number k in grlex ordering of integer numbers from 1 to n, and then the integer that occupies the k-th position in this ordering. 

```input1
20 10

2 14

提示

没有写明提示

题目来源

没有写明来源