(I)由{an}是公差不为零的等差数列,且a2=3,又a4,a5,a8成等比数列,知,由此能求出数列{an}的通项公式.
(II)由an=-2n+7,知=6n-n2,由an=Sn,得:-2n+7=6n-n2,由此能求出使an=Sn成立的所有n的值.
【解析】
(I)∵{an}是公差不为零的等差数列,
且a2=3,又a4,a5,a8成等比数列,
∴,
解得a1=5,d=-2,
∴an=5+(n-1)×(-2)=-2n+7.
(II)∵an=-2n+7,
∴a1=5,
=
=6n-n2,
由an=Sn,得:-2n+7=6n-n2,
∴n=1,或n=7.