The sequence begins with a0=2 and follows the formula.
This is what I came up with, but I'm not sure if I got this right.
Well, short answer - it is not correct. Because, you do not keep track on n-1
iteration value. You should use shift registers. And then, the solution to this task will be: