The sum of the first 7 terms of an AP is 49 and the sum of its first 17 term is 289. Find the sum of its first n terms.