设数列{an}满足a(n+1)=an2-nan+1,n=1,2,3,…当a1=2时,求an.