2 of 2
deleted 3 characters in body
bb94
  • 2.3k
  • 10
  • 16

Setanta, 79 bytes

gniomh(n){k:=1nuair-a 1{a:=k le i idir(1,k+1)ma k%i a-=1ma a==n toradh k k+=1}}

Try it here!

bb94
  • 2.3k
  • 10
  • 16