The sum of the floor function counts the integer points lying on or below a branch of the rectangular hyperbola $xy=n$ (for $x,y\gt 0$). Sketch this and add the square with corners $(0,0),(0,\sqrt n), (\sqrt n, 0), (\sqrt n, \sqrt n)$ (the last of these points lies on the hyperbola).
$k^2$ counts the points in the square, and the tails are symmetrical about $x=y$. The sum taken once counts the points in the tail, plus the points in the square (which are therefore counted twice when the sum is multiplied by $2$).
You should be able to turn these observations into a formal proof.
This is now the fourth time (at least) that a different form of question about this sum has been posed recently. The sum is equivalent to the sum of the divisor function $d(n)$, which counts the number of divisors of $n$.
Further note
If $(a,b)$ is below the hyperbola xy=n, so is $(b,a)$. Look at the sum on the right-hand side, taken once. It counts the number of points $(x,y)$ on the line $x=1$ with $0\lt xy \le n$ i.e. $\left\lfloor \frac n1 \right\rfloor$, the points with $x=2$ i.e. $\left\lfloor \frac n2 \right\rfloor$, up to the points with $x=k$ ie $\left\lfloor \frac nk \right\rfloor$.
Note that the points $(a,b)$ with $a,b \le k$ are all counted in this sum. No points with $a \gt k$ are counted.
The sum also counts the points in a similar way for $y=1, 2 \dots k$. This also has the points $(a,b)$ with $a,b\le k$ - we note there are $k^2$ of these, but has no points with $b\gt k$.
If we count the sum twice, we have counted all the points under the hyperbola, but there are $k^2$ points we have counted twice, so we subtract $k^2$ to avoid double-counting.
For other questions see this, and this.
I have written a proof for your equation ($4$) in the linked question, with the procedure to prove your ($1$) in this question being similar. First, to reduce the algebra involved, define
$$m = \lfloor \log_2 n \rfloor, \; \; j = \nu_2(n) \tag{1}\label{eq1A}$$
Since $m$ is the index of the largest non-zero binary coefficient of $n$, this means
$$n = \sum_{i = 0}^{m}c_i 2^i, \; 0 \le c_i \le 1 \; \forall \; 0 \le i \le m \tag{2}\label{eq2A}$$
Next, using \eqref{eq1A} and a change of the index variable, your ($3$) can be written as
$$\begin{equation}\begin{aligned}
n & = 1 + \sum_{k=1}^{\lfloor \log_2{n} \rfloor + 1} \left( \left\lfloor\frac{2n - 1 + 2^k}{2^{k+1}}\right\rfloor - \left\lfloor\frac{2n - 1 + 2^{k+1}}{2^{k+2}}\right\rfloor \right)k \\
& = 1 + \sum_{k=0}^{m} \left(\left\lfloor\frac{2n - 1 + 2^{k+1}}{2^{k+2}}\right\rfloor - \left\lfloor\frac{2n - 1 + 2^{k+2}}{2^{k+3}}\right\rfloor \right)(k + 1)
\end{aligned}\end{equation}\tag{3}\label{eq3A}$$
With just the first floor function value which is being summed, using \eqref{eq2A} gives
$$\begin{equation}\begin{aligned}
\left\lfloor\frac{2n - 1 + 2^{k+1}}{2^{k+2}}\right\rfloor & = \left\lfloor\frac{\sum_{i = 0}^{m}c_i 2^{i+1} + 2^{k+1} - 1}{2^{k+2}}\right\rfloor \\
& = \left\lfloor\frac{\sum_{i = k+1}^{m}c_i 2^{i+1} + \sum_{i = 0}^{k}c_i 2^{i+1} + 2^{k+1} - 1}{2^{k+2}}\right\rfloor \\
& = \left\lfloor\frac{\sum_{i = k+1}^{m}c_i 2^{i+1}}{2^{k+2}} + \frac{\sum_{i = 0}^{k}c_i 2^{i+1} + 2^{k+1} - 1}{2^{k+2}}\right\rfloor \\
& = \left\lfloor\sum_{i = k+1}^{m}c_i 2^{(i+1) - (k+2)} + \frac{\sum_{i = 0}^{k}c_i 2^{i+1} + 2^{k+1} - 1}{2^{k+2}}\right\rfloor \\
& = \sum_{i = k+1}^{m}c_i 2^{i-k-1} + \left\lfloor\frac{\sum_{i = 0}^{k}c_i 2^{i+1} + 2^{k+1} - 1}{2^{k+2}}\right\rfloor \\
& = \sum_{i = k+1}^{m}c_i 2^{i-k-1} + \left\lfloor\frac{(c_k + 1)\left(2^{k+1}\right) + (\sum_{i = 0}^{k - 1}c_i 2^{i+1} - 1)}{2^{k+2}}\right\rfloor \\
\end{aligned}\end{equation}\tag{4}\label{eq4A}$$
Note the numerator of the fraction in \eqref{eq4A} is greater than or equal to $2^{k+2}$ iff $c_k = 1$ and there's at least one $c_i = 1$ for some $0 \le i \le k - 1$, with the latter condition only being true if $k \gt j$. To make this simpler to handle, define a boolean type indicator function of
$$B(e) = \begin{cases}
0 & e \text{ is false} \\
1 & e \text{ is true}
\end{cases} \tag{5}\label{eq5A}$$
Using this function, \eqref{eq4A} can be simplified to
$$\left\lfloor\frac{2n - 1 + 2^{k+1}}{2^{k+2}}\right\rfloor = \sum_{i = k+1}^{m}c_i 2^{i-k-1} + c_{k}B(k \gt j) \tag{6}\label{eq6A}$$
The second floor function being summed is basically the same, but with the powers of $2$ being $1$ larger, so it becomes
$$\left\lfloor\frac{2n - 1 + 2^{k+2}}{2^{k+3}}\right\rfloor = \sum_{i = k+2}^{m}c_i 2^{i-k-2} + c_{k+1}B(k + 1 \gt j) \tag{7}\label{eq7A}$$
Using \eqref{eq6A} and \eqref{eq7A} gives
$$\begin{equation}\begin{aligned}
& \left\lfloor\frac{2n - 1 + 2^{k+1}}{2^{k+2}}\right\rfloor - \left\lfloor\frac{2n - 1 + 2^{k+2}}{2^{k+3}}\right\rfloor \\
& = \sum_{i = k+1}^{m}c_i 2^{i-k-1} + c_{k}B(k \gt j) - \left(\sum_{i = k+2}^{m}c_i 2^{i-k-2} + c_{k+1}B(k + 1 \gt j)\right) \\
& = \left(c_{k+1} + \sum_{i = k+2}^{m}c_i 2^{i-k-1}\right) + c_{k}B(k \gt j) - \sum_{i = k+2}^{m}c_i 2^{i-k-2} - c_{k+1}B(k + 1 \gt j) \\
& = \left(c_{k+1} + 2\sum_{i = k+2}^{m}c_i 2^{i-k-2}\right) - \sum_{i = k+2}^{m}c_i 2^{i-k-2} + c_{k}B(k \gt j) - c_{k+1}B(k + 1 \gt j) \\
& = \sum_{i = k+2}^{m}c_i 2^{i-k-2} + c_{k+1} + c_{k}B(k \gt j) - c_{k+1}B(k + 1 \gt j) \\
& = \left\lfloor\frac{n}{2^{k+2}}\right\rfloor + \left(c_{k+1} + c_{k}B(k \gt j) - c_{k+1}B(k + 1 \gt j)\right)
\end{aligned}\end{equation}\tag{8}\label{eq8A}$$
Next, define
$$f(k, j) = c_{k+1} + c_{k}B(k \gt j) - c_{k+1}B(k + 1 \gt j) \tag{9}\label{eq9A}$$
For $k \lt j - 1$, you get $c_{k} = c_{k+1} = 0$, so $f(k, j) = 0 = c_{k}$. With $k = j - 1$, you then get $c_{k} = 0$, $c_{k+1} = c_j = 1$, $B(k + 1 \gt j) = 0$, so $f(k, j) = c_{k+1} = c_j$. Next, with $k = j$, you get $B(k \gt j) = 0$, $B(k + 1 \gt j) = 1$, so $f(k, j) = c_{k+1} - c_{k+1} = 0$. Finally, for $k \gt j$, since $B(k, j) = B(k + 1 \gt j) = 1$, you have $f(k, j) = c_{k+1} + c_{k} - c_{k+1} = c_{k}$. In summary, then, you have $f(k,j) = c_k$ for all $k$ except for $k = j - 1$ where it's $c_j$ and for $k = j$ where it's $0$, i.e., those $2$ values are mixed around.
Note, though, if $j = 0$, then $k = j - 1 = -1$. Nonetheless, since the right side multiplier in \eqref{eq3A} for $k = -1$ is $k + 1 = 0$, so changing the starting index to $-1$ doesn't change the sum, I do this below in \eqref{eq10A} to use just one set of calculations for $j = 0$ and $j \gt 0$, and then switch back to starting at $k = 0$ near the end.
Using \eqref{eq9A} in \eqref{eq8A} and then substituting the result into \eqref{eq3A}, plus using the results & issues discussed in the above $2$ paragraphs including $c_{j-1} = 0$ and $c_j = 1$, and also what you're already noted that $c_k = \left\lfloor \frac{n}{2^{k}} \right\rfloor \bmod 2$, gives
$$\begin{equation}\begin{aligned}
n & = 1 + \sum_{k=0}^{m}\left(\left\lfloor\frac{n}{2^{k+2}}\right\rfloor + f(k,j)\right)(k + 1) \\
& = 1 + \sum_{k=0}^{m}\left\lfloor\frac{n}{2^{k+2}}\right\rfloor(k + 1) + \sum_{k=-1}^{m}f(k,j)(k + 1) \\
& = 1 + \sum_{k=0}^{m}\left\lfloor\frac{n}{2^{k+2}}\right\rfloor(k + 1) + \sum_{k=-1}^{j-2}c_k(k + 1) + c_j((j-1)+1) + \sum_{k=j+1}^{m}c_k(k + 1) \\
& = 1 + \sum_{k=0}^{m}\left\lfloor\frac{n}{2^{k+2}}\right\rfloor(k + 1) + \sum_{k=-1}^{j-1}c_k(k + 1) + (c_j)(j + 1) - 1 + \sum_{k=j+1}^{m}c_k(k + 1) \\
& = \sum_{k=0}^{m}\left\lfloor\frac{n}{2^{k+2}}\right\rfloor(k + 1) + \sum_{k=0}^{m}c_k(k + 1) \\
& = \sum_{k=0}^{m}\left[ \left\lfloor \frac{n}{2^{k+2}} \right\rfloor + \left(\left\lfloor \frac{n}{2^{k}} \right\rfloor \bmod 2 \right) \right](k+1)
\end{aligned}\end{equation}\tag{10}\label{eq10A}$$
Best Answer
In Apostol's Number Theory textbook it is shown using Euler's summation formula that for all $0<s<1$, $$ \sum_{k=1}^n\frac{1}{k^s}=\frac{n^{1-s}-1}{1-s}+1-s\int_1^n\frac{t-\lfloor t\rfloor}{t^{s+1}}\ dt\qquad (1). $$ Observe that for all $n>1$, $$ 0< \int_1^n\frac{t-\lfloor t\rfloor}{t^{s+1}}\ dt\leq \int_1^{\infty}\frac{1}{t^{s+1}}\ dt=\frac{1}{s}. $$ Using these bounds in $(1)$ implies that $$ 0\leq\sum_{k=1}^n\frac{1}{k^s}-\frac{n^{1-s}-1}{1-s}<1. $$ Consequently, it follows that $$ \left\lfloor\sum_{k=1}^n\frac{1}{k^s}\right\rfloor=\frac{n^{1-s}-1}{1-s} $$ whenever the right side is an integer. In particular, when $n=10^4$ and $s=\tfrac12$ the right side evaluates to the integer $198$, and this answers your question.
To answer your more general question, observe that our integer condition when $s=\tfrac12$ requires that $2(\sqrt{n}-1)$ be an integer, or equivalently, that $n$ is a perfect square. Thus, $$ q=2(\sqrt{n}-1), $$ whenever $n$ is a perfect square. For non-square $n$, our bounds imply that rounding $2(\sqrt{n}-1)$ will get you to within $1$ of the correct answer.