IMO 1984 LL GBR27

The function f(n) is defined on the nonnegative integers n by:

IMO 1984 LL GBR27

Origin: GBR

Problem

The function f(n) is defined on the nonnegative integers n by: f(0) = 0, f(1) = 1, f(n) = f  n −1 2m(m −1)  −f 1 2m(m + 1) −n  , for 1 2m(m −1) < n \leq1 2m(m + 1), m \geq2. Find the smallest integer n for which f(n) = 5.