$\{ \frac{n}{2^k} = x \}$ , A simple Question that's bothering me.

56 Views Asked by At

I'm quite fascinated by the above Simple question. i.e.,

If I just make $k$ as big as, say $k \ge 10^8 $ , then it's quite heavy to compute the value of $2^k$.

My query is, if that becomes the case, then Given the values of $n$ & $k$, how can we find $x$ alternatively which can be more efficient (efficient in a sense that, the process will be computationally cost effective)?

[ say, either by making the computationally costly operation $(2^k)$ as minimum as possible or by avoiding it completely ] ?

I'm curious about this.

EDIT $1$ :

And what if, $n$ is also large? (say, $n \geq 10^{18}$ )

2

There are 2 best solutions below

0
On BEST ANSWER

Perhaps try logarithm,$$x=\frac{n}{2^k}=\exp(\ln n - k \ln 2) $$

2
On

If you want it exactly there is not much to be done. $2^{10^8}$ has about $30,000,000$ decimal places. It is easy to compute in binary, if $n$ is supplied that way-just shift the radix point $10^8$ places and you are done.

Unless $n$ is very large, $x$ will be very close to $0$. Maybe $0$ is a good enough approximation. You can take logarithms and find $\log x = \log n - k\log 2$. That will easily give you the magintude of $x$.