Regular polygonal numbers and generalized Pell equations