题目描述
We define 123-numbers as follows:
- 1 is the smallest 123-number.
- When written in base 10 the only digits that can be present are “1”, “2” and “3” and if present the number of times they each occur is also a 123-number.
So 2 is a 123-number, since it consists of one digit “2” and 1 is a 123-number. Therefore, 33 is a 123-number as well since it consists of two digits “3” and 2 is a 123-number.
On the other hand, 1111 is not a 123-number, since it contains 4 digits “1” and 4 is not a 123-number.
In ascending order, the first 123-numbers are:
$1,2,3,11,12,13,21,22,23,31,32,33,111,112,113,121,122,123,131,\dots$
Let $F(n)$ be the $n-th$ 123-number. For example $F(4)=11$, $F(10)=31$, $F(40)=1112$, $F(1000)=1223321$ and $F(6000)=2333333333323$.
Find $F(111111111111222333)$. Give your answer modulo $123123123$.
题意
定义一种数字:
- 1是这种数字
- 如果一个数字在10进制下只包含1,2,3,并且这些数字出现的次数也是这种数字,那么这个数字也是这种数字。
将这种数字从小到大排序后得到一个序列,问你这个序列的第 $111111111111222333$ 项 % $123123123$。
分析
一个简单的想法是,对于每个固定长度的数字,我们可以得到所有可行的答案数。基于这个想法我们能很快定出答案的长度。
然后现在已经知道答案的长度了,我们可以枚举每一位答案,看当前位应该是几。
然后答案就很明显了。
代码
给大佬递上我奇丑无比的代码 (/ω\)
1 | num = [0,1,2,3,11,12,13,21,22,23,31,32,33,111,112,113,121,122,123,131] |