How to write an equation for the nth term