Given input of a positive integer n
, write a program that completes the following process.
- Find the smallest positive integer greater than
n
that is a perfect square and is the concatenation ofn
and some other number. The order of the digits ofn
may not be changed. The number concatenated onton
to produce a perfect square may be calledr_1
. - If
r_1
is not a perfect square, repeat the above process withr_1
as the new input to the process. Repeat untilr_k
is a perfect square, denoteds
. - Print the value of
sqrt(s)
.
Input can be taken in any format. You can assume that n
is a positive integer. If any r_k
has a leading zero (and r_k
≠0), the zero can be ignored.
Test cases
Here are some test cases. The process demonstrates the above steps.
Input: 23
Process: 23, 2304, 4
Output: 2
Input: 10
Process: 10, 100, 0
Output: 0
Input: 1
Process: 1, 16, 6, 64, 4
Output: 2
Input: 5
Process: 5, 529, 29, 2916, 16
Output: 4
Input: 145
Process: 145, 145161, 161, 16129, 29, 2916, 16
Output: 4
Input: 1337
Process: 1337, 13373649, 3649, 36493681, 3681, 368102596, 2596, 25969216, 9216
Output: 96
This is code golf. Standard rules apply. The shortest answer (in bytes) wins.