题库练习 Make a Square
← 上一题 下一题 →

A11714 | Make a Square

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You are given a positive integer $n$ , written without leading zeroes (for example, the number 04 is incorrect).

In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.

Determine the minimum number of operations that you need to consistently apply to the given integer $n$ to make from it the square of some positive integer or report that it is impossible.

An integer $x$ is the square of some positive integer if and only if $x=y^2$ for some positive integer $y$ .

输入格式

The first line contains a single integer $n$ ( $1 \le n \le 2 \cdot 10^{9}$ ). The number is given without leading zeroes.

输出格式

If it is impossible to make the square of some positive integer from $n$ , print -1. In the other case, print the minimal number of operations required to do it.

输入输出样例

输入 #1
8314
输出 #1
2
输入 #2
625
输出 #2
0
输入 #3
333
输出 #3
-1
C++ 编辑器
输入
输出