#P6921. [ICPC2016 WF] Forever Young

[ICPC2016 WF] Forever Young

题目描述

My birthday is coming up. Alas, I am getting old and would like to feel young again. Fortunately, I have come up with an excellent way of feeling younger: if I write my age as a number in an appropriately chosen base bb, then it appears to be smaller. For instance, suppose my age in base 1010 is 3232. Written in base 1616 it is only 2020!

However, I cannot choose an arbitrary base when doing this. If my age written in base bb contains digits other than 00 to 99, then it will be obvious that I am cheating, which defeats the purpose. In addition, if my age written in base bb is too small then it would again be obvious that I am cheating.

Given my age yy and a lower bound \ell on how small I want my age to appear, find the largest base bb such that yy written in base bb contains only decimal digits, and is at least \ell when interpreted as a number in base 1010.

输入格式

The input consists of a single line containing two base 10 integers yy (10y101810 \le y \le 10^{18} – yes, I am very old) and \ell (10y10 \le \ell \le y).

输出格式

Display the largest base bb as described above.

题目大意

题目大意

我的生日快到了!唉,但如今我已经老了,我想重新获得年轻的感觉。

幸运的是,我想出了一个让人感觉更年轻的好方法:如果我把我的年龄以适当选择的bb进制书写,那么它看起来会更小。例如,假设我以1010进制书写的年龄是3232岁;以1616进制书写,它只有2020(0x200x20)!

然而,在这样做时,我不能选择任意进制数。如果以bb进制为数写的我的年龄包含090-9以外的数字,那么很明显我在作弊,这违背了目的。此外,如果我的年龄的进制数bb太小,那么很明显我在作弊。

在我希望我的年龄看起来有多小的问题上,考虑到我的年龄yy和下限ll,找到最大的进制数bb,这样写在基数bb中的yy只包含十进制数字,并且当将其看做一个十进制数字时至少是ll

输入格式

输入由一行组成,其中包含两个1010进制的整数yy (10y101810\le y\le10^{18} –是的,我很老)和ll(10ly10\le l \le y)

输出格式

如上所述,输出最大进制数bb

说明/提示

时间限制:1s1s,内存限制:1GB1GB

(洛谷这里实际是512MB512MB,但原题是1GB1GB)

20162016年国际大学生编程大赛ACMACM-ICPCICPC世界总决赛

32 20

16

2016 100

42

提示

Time limit: 1000 ms, Memory limit: 1048576 kB.

International Collegiate Programming Contest (ACM-ICPC) World Finals 2016