TITLE: Find an integer such that when squared, the first 4 digits are '6666'.
QUESTION [29 upvotes]: The title says it all. I'm simply looking for a proof to my answer of 2582. I used an obscure method that I perceived would yield the answer but I have no idea why it works.
I first calculated the square of the ceiling value of the square root of 6666. That didn't work so my intuition told me to repeat that process with 66660 instead of 6666. That still didn't work. It took me till the iteration with replacing 6666 with 6666000 to find that the square of the ceiling function of the square root of 6666000 is 6666724, the integer responsible being 2582.
Can someone please help? I found the answer but I want a more mathematical reasoning to my answer.

REPLY [3 votes]: One methodical way to find the answer with just pencil and paper
is to use the "long division" algorithm for extracting a square root.
The first step of this algorithm is to group the digits of your input number
in pairs. For example, to take the square root of $6666$, we first write
$$ \sqrt{66 \; 66}. $$
The first few steps of the algorithm result in
\begin{array}{r}
                         8 \;\phantom{0}1  \\[-3pt]
                4 \sqrt{66 \; 66} \\[-3pt]
             \underline{64}\;\phantom{66} \\[-3pt]
16\underline1|\phantom{0}2 \; 66 \\[-3pt]
              \underline{1 \; 61}\\[-3pt]
      162\underline{\ } |1 \; 05 \\[-3pt]
\end{array}
The next step in the usual algorithm is to append a pair of zeros after
the decimal point of the number under the square root in order to calculate
one additional digit after the decimal point of the result.
Alternatively, however, we can simply insert a pair of zeros to the left
of the decimal point, that is, multiply the number under the square root
sign by $100$. All the previous steps remain valid, and we can append one
digit to the result; that is, if we had previously set up to calculate
$\sqrt x$, we now calculate $\sqrt{100x} = 10 \sqrt x$:
\begin{array}{r}
                        8 \;\phantom{0}1 \;\phantom{0}6 \\[-3pt]
               4 \sqrt{66 \; 66 \; 00} \\[-3pt]
            \underline{64}\;   \phantom{66 \; 00} \\[-3pt]
16\underline1|\phantom{0}2 \; 66  \phantom{\; 00}\\[-3pt]
              \underline{1 \; 61} \phantom{\; 00}\\[-3pt]
       162\underline{6} |1 \; 05 \; 00 \\[-3pt]
                   \underline{97 \; 56} \\[-3pt]
                               7 \; 44
\end{array}
Now, in any "fully worked" example of the "long division" algorithm for the square root such as the example above, let $x$ be the number under the square root sign, let $y$ be the result (one digit for each pair of digits in $x$), and let $R$ be the result of the last subtraction step.
In the example above, $x = 66600$, $y = 861$, and $R = 744$.
Then in general,
$$ y^2 = x - R.$$
This is an essential part of how the "long division" algorithm for the square root works. As a result, if we start with $x=6666$ and keep appending pairs of zeros to $x$, we will always have
$y^2 = 6666 \times 10^n - R$, where $n$ is even. But because $6666$ is not a
perfect square, $R$ will never be zero, so $y^2$ will always be somewhat 
less than $6666 \times 10^n$, and it will never have $6666$ as its first
four digits.
So instead of $6666$, we can put $6667$ under the square root sign. Then we
will compute $y$ such that 
$$y^2 = 6666 \times 10^n + 10^n - R,$$
so the first four digits of $y^2$ will be $6666$
if and only if $R \leq 10^n$. But we will never find that $R$ is an even power of ten (for the same reason that $6666 \times 10^n$ will never be a perfect square), so actually we require $R < 10^n$.
In short, we take the square root of $6667 \times 10^n$ for even $n$,
using the "long division" square-root algorithm, increasing $n$ by two
until the remainder of the last subtraction step has no more digits than the
number of trailing zeros under the square root sign.
At that point, the result of the algorithm is the desired number.
This occurs when we have four digits in the result:
\begin{array}{r}
                         8 \;\phantom{0}1 \;\phantom{0}6 \;\phantom{0}5 \\[-3pt]
                4 \sqrt{66 \; 67 \; 00 \; 00} \\[-3pt]
             \underline{64}\;   \phantom{66 \; 00\; 00} \\[-3pt]
16\underline1|\phantom{0}2 \; 67  \phantom{\; 00\; 00}\\[-3pt]
              \underline{1 \; 61} \phantom{\; 00\; 00}\\[-3pt]
       162\underline{6} |1 \; 06 \; 00 \phantom{\; 00}\\[-3pt]
                   \underline{97 \; 56} \phantom{\; 00}\\[-3pt]
 1632\underline{5} |\phantom{0}8 \; 44 \; 00 \\[-3pt]
                    \underline{8 \; 16 \; 25}\\[-3pt]
                                    27 \; 75
\end{array}
Checking the result, we find that indeed
$$ 8165^2 = 66667225 = 6667 \times 10^4 - 2775,$$
as expected.
We can continue appending pairs of zeros to find larger numbers with the
desired property. Actually, for any larger numbers of digits we will find
a range of answers, the maximum being the number found by the algorithm
and the minimum being $8165$ followed by some zeros.
Of course this gives us only numbers whose square is $6666$ followed by an
even number of digits. To find numbers whose square is $6666$ followed by an
odd number of digits, we need to start with $66670$ rather than $6667$.
When applying the square root algorithm to a number with an odd number of
digits, we treat the first digit as a "pair" by itself, so the
algorithm proceeds like this:
\begin{array}{r}
                      2 \;\phantom{0}5 \;\phantom{0}8 \;\phantom{0}2 \\[-3pt]
                4 \sqrt{6 \; 66 \; 70 \; 00} \\[-3pt]
             \underline{4}\; \;\phantom{6 \; 00\; 00} \\[-3pt]
           4\underline5|2 \; 66  \phantom{\; 00\; 00}\\[-3pt]
             \underline{2 \; 25} \phantom{\; 00\; 00}\\[-3pt]
50\underline{8}|\phantom{0}\;41 \; 70 \phantom{\; 00}\\[-3pt]
                  \underline{40 \; 64} \phantom{\; 00}\\[-3pt]
  516\underline{2}|\phantom{0}1 \; 06 \; 00 \\[-3pt]
                   \underline{1 \; 03 \; 24}\\[-3pt]
                                    2 \; 76
\end{array}
So the algorithm comes up with your number $2582$ directly.
And indeed we find that
$$ 2582^2 = 6666724 = 6667 \times 10^3 - 276.$$