Finding the next term and rule for the nth term