当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6659:Acesrc and Good Numbers

题目描述
Acesrc is a famous mathematician at Nanjing University second to none. Playing with interesting numbers is his favorite. Today, he finds a manuscript when cleaning his room, which reads

... Let $f(d, n)$ denote the number of occurrences of digit $d$ in decimal representations of integers $1, 2, 3, \cdots, n$. The function has some fantastic properties ...

... Obviously, there exist some nonnegative integers $k$, such that $f(d, k) = k$, and I decide to call them $d$-good numbers ...

... I have found all $d$-good numbers not exceeding $10^{1000}$, but the paper is too small to write all these numbers ...

Acesrc quickly recollects all $d$-good numbers he found, and he tells Redsun a question about $d$-good numbers: what is the maximum $d$-good number no greater than $x$? However, Redsun is not good at mathematics, so he wants you to help him solve this problem.
输入解释
The first line of input consists of a single integer $q$ $(1 \leq q \leq 1500)$, denoting the number of test cases. Each test case is a single line of two integers $d$ $(1 \leq d \leq 9)$ and $x$ $(0 \leq x \leq 10^{18})$.
输出解释
For each test case, print the answer as a single integer in one line. Note that $0$ is trivially a $d$-good number for arbitrary $d$.
输入样例
3
1 1
1 199999
3 0
输出样例
1
199990
0
来自杭电HDUOJ的附加信息
Recommend chendu

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6659

最后修改于 2020-10-25T23:33:15+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/2000MS(Java/Others) 131072/131072K(Java/Others)