Code for recurrence relations problem.