Rakuten Kobo Interview Question

A maths question which ended up being a recursive function.