You say you have a number of 6 Megabits, that is $n < 2^{6,000,000}$.
We want to find numbers $b^k$ where b and k are integers, $2 ≤ b < 2^{31}$, k as large as possible such that $b^k ≤ n$, we you want to find the pair b, k that makes $n-b^k$ as small as possible. Since n is fixed, this is equivalent to making $n / b^k$ as small as possible, or making $\log n - k \cdot \log b$ as small as possible.
We find potential candidates by calculating k using double precision floating-point arithmetic. We calculate x = $\log n \div \log b$, and k = $\lfloor x \rfloor$. Then we calculate $\log n - k \cdot \log b$, and pick the b, k where this is smallest.
We need to be careful because of rounding errors in floating point arithmetic: So we can't just choose b, k which make $\log n - k \cdot \log b$ according to our calculation. We also need to consider all b', k' which may give the same or worse results due to rounding errors, but in reality might be better.
We also need to be careful if $x = \log n - k \cdot \log b$ is so close to the nearest integer that we can't determine $k = \lfloor x \rfloor$ for sure. In these cases, let k' = x rounded to the nearest integer and k = k' - 1 (these are the two possible values); we process (b, k) like every other pair, but must consider (b, k') to be a candidate as well.
If b is large then we can save more time: For example, if n is a 6 million bit number, then for b ≥ 70,000 there will always be two or more consecutive values b with the same k. If b is close to $2^{31}$, we find that over 200,000 consecutive values b have the same k. So for large b, we instead find the largest b for a fixed k: b = $\lfloor \exp (\log n \div (k + 1)) \rfloor$; this substantially reduces the amount of work.
Once we have a small number of candidates, to avoid having to figure out whether say $2^{1,234,568}$ or $4^{617,284}$ are closer to n, we exclude values b which are powers of some smaller number.
Then we first examine all the pairs (b, k') where the calculated x was very close to an integer: We have to calculate $b^{k'}$ exactly, reject it if it is greater than n, otherwise keep the smallest one. If none of these were accepted, we examine all the other candidates that might be optimal.
For a 6 million bit number n, if we examine individual b's up to about 50,000 and then switch to examining individual k, we have about 250,000 values to examine. With a bit of luck there is only one pair (b, k) that could be the best, so we only have a few million floating point operations, which should run in a few milliseconds.
(What is the problem with x close to an integer? Say we have $n = 7^{1,000,000} - 1$ and $n' = 7^{1,000,000} + 1$. With b = 7, we will get x = 1,000,000 or something very close, but in both cases we don't actually know whether k should be 999,999 or 1,000,000. So we have to try 1,000,000 separately. $7^{1,000,000} then turns out to be too large in the first case).
If you only want to find the best b, k and not the actual remainder, you may be able to do without high-precision arithmetic altogether.