0
$\begingroup$

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?

$\endgroup$
4
  • $\begingroup$ $\log_{10}(10^2) = 2$ but $100$ has 3 digits. Add 1. $\endgroup$
    – wlad
    Jun 24, 2015 at 18:17
  • 1
    $\begingroup$ $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$? $\endgroup$ Jun 24, 2015 at 18:19
  • $\begingroup$ 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??? $\endgroup$ Jun 24, 2015 at 18:19
  • $\begingroup$ $n^2$ is the smallest 3-digit number in base $n$. $\endgroup$
    – wlad
    Jun 25, 2015 at 8:10

2 Answers 2

1
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$ Jun 24, 2015 at 18:22
1
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .