Skip to main content
3 of 3
added 547 characters in body
tsh
  • 35.5k
  • 2
  • 34
  • 129

JavaScript (Node.js), 63 bytes

f=(n,m=2,i=0,p=n-i**m)=>p<0?f(n,m+1):!p||i&&f(p)<m?m:f(n,m,i+1)

Try it online!

Time out for not so large n as its terrible recursion design. It could be fast if we apply memorize to it (70 bytes).

f=(n,m=2,i=0,p=n-i**m)=>f[n]??=p<0?f(n,m+1):!p||i&&f(p)<m?m:f(n,m,i+1)

o.value = [...Array(50000)].map((_, i) => i).filter(v => f(v) > 5).join(', ')
<a href="https://oeis.org/A111151">A111151</a>: <output id=o></output>

tsh
  • 35.5k
  • 2
  • 34
  • 129