To find the closest representation $n^a$ for some positive integer $N$ we just bruteforce all the logs: $\log_2 N$, $\log_3 N$, ... and compare all the results to determine which one is the closest.
For example, how to find the closest $N = n^a$ for $N$ = 127:
The first check: $\log_2 127= 7$ gives us a very close $n^a$ which is $128$, but how do we know it's the closest one, without checking other possible $n^a$ ?
Question 1:
Do we have to use described above bruteforce method to find $n^a$ the closest to some $N$ ?
for example: $N = 2403$, do we just bruteforce and compare all the logs up until $\log_7$ at which point we find that the $\log_7 2403 = 4$ is the closest possible $N = n^a$ for $N = 2403$ ?
Question 2:
- How would we find not just the closest $N = n^a$ but the closest $N = n^a + m^b$ (let's use the same integer $N = 2403$ for the example) ?
Rather than looking at bases, look at exponents.
Start with $a = \lceil\log_2(n)\rceil$. This is the highest interesting exponent. Then for each integer exponent at and below that calculate $[N^{-a}]^a$, where $[x]$ is $x$ rounded to the nearest integer.