How many square numbers exist that have the length $N$ in the decimal system?
E.g. for the length $N=1$ there exist 4 square numbers (0, 1, 4, 9).
Thank you
How many square numbers exist that have the length $N$ in the decimal system?
E.g. for the length $N=1$ there exist 4 square numbers (0, 1, 4, 9).
Thank you
On
$N=2$ squares are $10-4=6$. For $N=3$ squares are $31-10=21$...
If we call $q(N)$ the number of squares with $N$ digits then
$q(N)=\left\lceil\sqrt{10^N}\right\rceil-\left\lceil\sqrt{10^{N-1}}\right\rceil$
On
Believe it or not.
If $N$ is odd, take $\sqrt{10} -1=2.1622776601683793319988935444327$ and multiply by $10^{\frac {N-1}2}$ and round up.
If $N$ is even, take $10 - \sqrt{10} = 6.8377223398316206680011064555673$ and multiply by $10^{\frac N2 -1}$ and round down.
That is because $10^{\frac {N-1}2}(\sqrt{10} - 1) = 10^{\frac N2 -1}(10 - \sqrt{10}) = 10^{\frac {N}2}- 10^{\frac {N-1}2} = \sqrt{10^N} - \sqrt{10^{N-1}}$.
$\sqrt{10^N}$ will be (with rounding) the number of perfect squares up to $10^N$ and $\sqrt{10^{N-1}}$ will be (with rounding) the number of perfect squares up to $10^{N-1}$. The difference will be the number of perfect squares between the two, which will all have $N$ digits.
(You round up if $N$ is odd because the first $N$ digit number, $10^{N-1}$ will be a perfect square. You round down if $N$ is even because the first $N$ digit number will not be. The last $N$ digit number, $10^N -1$ is never a perfect square.)
Tedious details below:
==== old answer below:======
The smallest number with $N$ digits is $10^{N-1}$. This is a perfect square if and only if $\sqrt{10^{N-1}}$ is an integer. If not the first perfect square will be $m^2$ where $m = \lceil \sqrt{10^{N-1}}\rceil$.
The last $N$ digit number is $10^N -1$ and the last perfect square is $n=\lfloor \sqrt{10^{N}-1} \rfloor$.
Note $10^{N}-1 = 9*111111.......1$, [can not be a perfect square][1].
So the number of perfect squares are $n-m + 1$.
Case 1: $N-1$ is even. Then $m = 10^{\frac{N-1}2}$
Neither $10^N$ nor $10^N -1$ are perfect squares so $m =\lfloor 10^{\frac N2}\rfloor$
So $n-m + 1 = \lfloor 10^{\frac N2}\rfloor - 10^{\frac{N-1}2}+1 = \lceil 10^{\frac N2} - 10^{\frac{N-1}2\rceil}$
$\lceil (\sqrt{10}-1)10^{\frac{N-1}2}\rceil$
Case 2: $N$ is even.
Then $n = 10^{\frac N2} - 1$ and $10^{\frac {N-1}2} < m <10^{\frac {N-1}2}+1$
So $10^{\frac N2} - 10^{\frac {N-1}2}-1 < n-m + 1<10^{\frac N2} - 10^{\frac {N-1}2}$
So $n-m+1 = \lfloor 10^{\frac N2} - 10^{\frac {N-1}2} \rfloor$
$\lfloor 10^{\frac {N-1}2}(\sqrt{10} - 1)\rfloor$
So there are approximately, $10^{\frac {N-1}2}(\sqrt{10} - 1)$ (which is never an integer) $N$-digit perfect squares. Round up if $N$ is odd; round down if $N$ is even.
Test: Then should be $\lfloor 10^{\frac {5}2}(\sqrt{10} - 1)\rfloor= \lfloor 1000 - 100\sqrt{10}\rfloor = 683$ $6$ digit perfect squares. From $317^2 = 100489$ to $999^2=998001$. So that is $683$ squares.
Whoa.... just realized something. $\sqrt {10} - 1 = 2.1622776601683793319988935444327$ so if $N$ is odd there will be $10^{\frac{N-1}2}*2.1622776601683793319988935444327$ rounded up. $3$ one digit squares (1,4,9). and $22$ $3$ digit squares (from $100 = 10^2$ to $31^2 =961$ and so on.
And if $N$ is even, $10- \sqrt{10} = 6.8377223398316206680011064555673$ so there will be $10^{\frac {N-2}2}*6.8377223398316206680011064555673$ rounded down. Ex. $6$ $2$ digit squares ($16=4^2$ to $81=9^2$) and $68$ $4$ digit squares. (From $32^2 = 1024$ to $99^2 = 9801$.
And so on.
A number $m$ has $d$ digits when
$$10^{d-1}\le m<10^d.$$
A perfect square $n^2$ has $d$ digits when
$$10^{d-1}\le n^2<10^d$$ or $$\sqrt{10}^{d-1}\le n<\sqrt{10}^d.$$
Turning to integer bounds,
$$\left\lceil\sqrt{10}^{d-1}\right\rceil\le n<\left\lceil\sqrt{10}^d\right\rceil$$ gives you the answer.
Note that we can distinguish two cases on the parity of $d$:
$d:=2k-1\to 10^{k-1}\le n<10^{k-1}\sqrt{10}$,
$d:=2k\to 10^{k-1}\sqrt{10}\le n<10^k$,
and you can "read" all the requested counts from the expansions
$\sqrt{10}-1\to21622776601683793319988935444327\cdots$
$10-\sqrt{10}\to68377223398316206680011064555673\cdots$
taking $d/2$ digits from the left, alternatively and adding one for odd $d$.
For increasing $d$,
$$3,6,22,68,217,683,2163,6837,\cdots.$$
(The first count is $3$ because $0$ is considered a zero-digits number.)