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$
  • $\begingroup$ $\log_{10}(10^2) = 2$ but $100$ has 3 digits. Add 1. $\endgroup$ – jkabrg Jun 24 '15 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$ – hexaflexagonal Jun 24 '15 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$ – barak manos Jun 24 '15 at 18:19
  • $\begingroup$ $n^2$ is the smallest 3-digit number in base $n$. $\endgroup$ – jkabrg Jun 25 '15 at 8:10
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$
  • $\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$ – hexaflexagonal Jun 24 '15 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$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.