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

建议使用的浏览器:

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

6831:Fragrant numbers

题目描述
Many people love numbers, and some have a penchant for specific numbers. Nowadays in popular culture, 1145141919 is a very fragrant number, and many people want to represent all other numbers with this number.

Let $S$ be an infinite string of "1145141919" infinitely stitched together as "114514191911451419191145141919...".

Take a prefix $T$ of $S$ , you can insert '$($' , '$)$' , '$+$' or '$*$' to $T$ to form a new string $T'$, and then let the value of $T'$ be $val(T')$ according to ordinary rules. (You can insert any number of operators, even 0. But need to ensure that the inserted operators form legitimate operations)

Now for a number $N$, please calculate the minimum length of $T$ that can make $val(T')=N$. For example, when $N=520$, the minimum length of $6$ (pick the first $6$ characters $114514$ and insert operators to make $T'=1+1+4+514$ , then we have $val(T')=520$ )

If no such $T$ exists, output $-1$.
输入解释
There are multiple test cases.

The first line with a number $t$ indicates the number of test cases.

For each test case, one integer $N$ per line indicates an inquiry.

$1≤t≤30$

$1≤N≤5000$
输出解释
Output $t$ lines.

One integer per line indicates the corresponding answer.
输入样例
3
520
1
2
输出样例
6
1
2
来自杭电HDUOJ的附加信息
Recommend IceyWang

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

源链接: HDU-6831

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

共提交 0

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