Finding the first three terms and nth term of a sequence