Problem 3042 --Acesrc and Good Numbers

3042: Acesrc and Good Numbers

"
Time Limit $2$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $1$ 正确数量 $1$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
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)f(d,n) denote the number of occurrences of digit dd in decimal representations of integers 1,2,3,⋯,n1,2,3,⋯,n. The function has some fantastic properties ...
... Obviously, there exist some nonnegative integers kk, such that f(d,k)=kf(d,k)=k, and I decide to call them dd-good numbers ...
... I have found all dd-good numbers not exceeding 101000101000, but the paper is too small to write all these numbers ...

Acesrc quickly recollects all dd-good numbers he found, and he tells Redsun a question about dd-good numbers: what is the maximum dd-good number no greater than xx? 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 qq (1≤q≤1500)(1≤q≤1500), denoting the number of test cases. Each test case is a single line of two integers dd (1≤d≤9)(1≤d≤9) and xx (0≤x≤1018)(0≤x≤1018)
For each test case, print the answer as a single integer in one line. Note that 00 is trivially a dd-good number for arbitrary dd.
3
1 1
1 199999
3 0
1
199990
0

推荐代码 查看3042 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$257 $ms] 淡意的温柔 591134 2020-06-06 08:38:05
内存最少[$0 $KB] 淡意的温柔 591134 2020-06-06 08:38:05
第一AC 淡意的温柔 591134 2020-06-06 08:38:05
第一挑战 淡意的温柔 591134 2020-06-06 08:38:05

赛题来源/所属竞赛 2019 Multi-University Training Contest 8 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛