CF49B.Sum

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying a + b = ?, and that the base of the positional notation wasn’t written anywhere. Now Vasya has to choose a base p and regard the expression as written in the base p positional notation. Vasya understood that he can get different results with different bases, and some bases are even invalid. For example, expression 78 + 87 in the base 16 positional notation is equal to _FF_16, in the base 15 positional notation it is equal to 11015, in the base 10 one — to 16510, in the base 9 one — to 1769, and in the base 8 or lesser-based positional notations the expression is invalid as all the numbers should be strictly less than the positional notation base. Vasya got interested in what is the length of the longest possible expression value. Help him to find this length.

The length of a number should be understood as the number of numeric characters in it. For example, the length of the longest answer for 78 + 87 = ? is 3. It is calculated like that in the base 15 (11015), base 10 (16510), base 9 (1769) positional notations, for example, and in some other ones.

瓦西娅正在学习进位制记数法。不幸的是,他常常忘记在表达式旁注明所使用的进位制底数。有一次,他在笔记本上看到一条记录:a+b=?a + b = ?,但该表达式所用的进位制底数却未被写出。现在瓦西娅需要选择一个底数 pp,并将该表达式视作以 pp 为底的进位制记数法来理解。瓦西娅意识到,不同底数会得到不同的结果,且某些底数甚至无效。例如,表达式 78+8778 + 87 在十六进制(底数为 1616)下等于 FF16\text{FF}_{16},在十五进制(底数为 1515)下等于 11015110_{15},在十进制(底数为 1010)下等于 16510165_{10},在九进制(底数为 99)下等于 1769176_9;而在八进制或更小底数的进位制中,该表达式是无效的,因为所有数字必须严格小于进位制底数。

瓦西娅开始好奇:所有可能的有效底数下,表达式结果的最长长度是多少?请你帮他找出这个最大长度。

此处,“一个数的长度”定义为该数在对应进位制下所含的数字字符个数。例如,对于 78+87=?78 + 87 = ?,其所有可能答案中最长的长度为 33,这在十五进制(11015110_{15})、十进制(16510165_{10})、九进制(1769176_9)等进位制下均可达到,且也存在于其他一些进位制中。

输入格式

The first letter contains two space-separated numbers a and b (1 ≤ a, b ≤ 1000) which represent the given summands.

第一个字母包含两个以空格分隔的数字 aa 和 bb(1 ≤ a, b ≤ 10001 ≤ a, b ≤ 1000),表示给定的加数。

输出格式

Print a single number — the length of the longest answer.

输出一个数字——最长答案的长度。

输入输出样例

  • 输入#1

    78 87

    输出#1

    3
  • 输入#2

    1 1

    输出#2

    2

输入解题思路,AI测评打分。不知道怎么写?

首页