Given
#color(white)("XXX")S=(n(a+1))/2color(white)("XX")#...at least that's how interpreted the question.
#(n(a+1))/2 = Scolor(white)("XXXX")#because we usually like to have the variable we are solving for on the left.
#rarr n(a+1) = 2Scolor(white)("XXXX")#after multiplying both sides by #2#
#rarr n= (2S)/(a+1)color(white)("XXXX")#after multiplying both sides by #(a+1)# and with the assumption that #a!=-1##