# Maximum number of digits in numbers between 0 to $n^2-1$ of base n

The number of digits in numbers between 0 and $n^2-1$ of base n is obtained by

$\log_n(n^2) = 2\log_nn = 2$

But why log is being used? I mean how doing log gives correct answer always?

• $\log_{10}(10^2) = 2$ but $100$ has 3 digits. Add 1. – jkabrg Jun 24 '15 at 18:17
• $n^2$ in base $n$ is always $100$. The number of digits is then constant: $3$. Maybe you're looking for the number of digits in $n^2$ for base $b$? – hexaflexagonal Jun 24 '15 at 18:19
• The number of digits in the square of a number n of base The number of digits in the square of a number $n$ of base $n$ is $3$ regardless of the value of $n$. Why make things any more complicated than that??? – barak manos Jun 24 '15 at 18:19
• $n^2$ is the smallest 3-digit number in base $n$. – jkabrg Jun 25 '15 at 8:10

In base $n$, $n$ is represented as $10_n$. So $$10_n^2 = 100_n$$ That's 3 digits.

Now $1+\log_n(n^2) = 3$. Done.

• I'm not going to downvote this, but you should keep an eye on it and delete it if the original question is edited. I think it's possible that OP mistyped. – hexaflexagonal Jun 24 '15 at 18:22

About the number of digits of a number $n^2$ in base $b$:

Let $n$ have the representation $$n = (d_{m-1} \cdots d_1 d_0)_b = \sum_{k=0}^{m-1} d_k b^k$$ with $m$ digits from $\{ 0, \ldots, b-1 \}$. Then we have $$n < b^m \Rightarrow n^2 < b^{2m}$$ This means $n^2$ has at most $2m-1$ digits.

To derive $m$ for a given $n$ we use some logarithm: $$n < b^m \Rightarrow \\ \log n < \log b^m = m \log b \Rightarrow \frac{\log n}{\log b} < m$$ The smallest $m$ should be $$m = \left\lfloor \frac{\log n}{\log b} \right\rfloor + 1$$ The special case $b = n$ gives $m = 2$ and that $n^2$ has at most $3$ digits.

As pointed out by fellow users $n^2 = (100)_n$ has exactly $3$ digits, which means that your formula, which gives $2$ digits, is not correct.