Skip to main content
4 of 4
Commonmark migration

JavaScript (ES6), 28 bytes

n=>g=(x=2)=>++n%x?--x:g(++x)

Test it

o.innerText=(f=

n=>g=(x=2)=>++n%x?--x:g(++x)

)(i.value=2521)();oninput=_=>o.innerText=f(+i.value)()
<input id=i><pre id=o>

Shaggy
  • 43.5k
  • 4
  • 36
  • 94