# [Jelly], 15 bytes

    µ<1ạḤðŒRṗAS$Þ⁸ị

[Try it online!][TIO-j9k310nk]

[Jelly]: https://github.com/DennisMitchell/jelly
[TIO-j9k310nk]: https://tio.run/##ASsA1P9qZWxsef//wrU8MeG6oeG4pMOwxZJS4bmXQVMkw57igbjhu4v///8xMv8z "Jelly – Try It Online"

1-indexed.

Inverse:

    AṀ×LŒRṗLAS$Þiµ:2NḂ}¡

[Try it online!][TIO-j9k31f0p]

[TIO-j9k31f0p]: https://tio.run/##y0rNyan8/9/x4c6Gw9N9jk4Kerhzuo9jsMrheZmHtloZ@T3c0VR7aOH///@jDXUUgMggFgA "Jelly – Try It Online"