I've been tasked with writing a program to find a $a_k$ member of a sequence:
$ a_0=4=2^2, a_1=8=2^3, a_2=9=3^2, a_3=16=4^2=2^4, a_4=25=5^2, a_5=27=3^3, a_6=32=2^5 $
and so on. I've coded up a brute-force solution, which takes advantage of $m^n$s logarithmic contours for $m>2$ and $n>2$:
The checking for each following member goes right-to-left through the table below, checking max $m$ for every $n$ and filtering out the repeated values (i.e. $64=8^2=4^3=2^6$). However, the method is too slow for me and I was wondering if there was a way to get to that $a_k$ element ($1<=k<=10^6$) by expressing this sequence as a formula? Thanks in advance.



This problem seems difficult, see the information provided in OEIS. However, brute force approaches give some results.
One may for instance list all numbers satisfying your conditions, until a given maximal value, and then sort them. The maximal value must be large enough to reach $k$ values (it seems from experiments and OEIS that it should be close tp $k^2$).
The following Python code makes the job, if I am correct:
Notice that it uses a
setto avoid duplicates, and that a full answer would have to findsqrt_max_valautomatically (by increasing it and adapting therange, typically). Many optimizations are still possible.