0

Sorry for my bad English.

I started to read book about algorithms(Introduction to Algorithms) and there is a problem, I should find a valid $n$ for $$n \times \log_2(n) = q $$ q might be very big number ($3\times10^{15}$)

I know that I can write a regular brute force program, but it doesn't work, if q is very large number.

1 Answers1

0

With $\log_2(n) = \frac{\ln(n)}{\ln(2)}$ your equation becomes \begin{align} n \frac{\ln(n)}{\ln(2)} &= q \\ \Leftrightarrow n \ln(n)&= q\ln(2) \\ \Leftrightarrow n \ln(n)&= \widetilde{q}. \end{align} Then, perform the change of variables $\widetilde{n} := \ln(n)$. This implies that $e^\widetilde{n} = e^{\ln(n)} = n$. Thus, your equation becomes

\begin{align} \widetilde{n} e^{\widetilde{n}} = \widetilde{q}. \end{align} Using the Lambert W function, this can be then be (numerically) solved for $\widetilde n = W(\widetilde q)$ and then $n$.

Dan Doe
  • 2,229