The equation for n layers is S(n) = n(n+1)(2n+1)/6
It is simplest to prove it by induction.
When n = 1,
S(1) = 1*(1+1)(2*1+1)/6 = 1*2*3/6 = 1.
Thus the formula is true for n = 1.
Suppose it is true for n = m. That is, for a pyramid of m levels,
S(m) = m*(m+1)*(2m+1)/6
Then the (m+1)th level has (m+1)*(m+1) oranges and so
S(m+1) = S(m) + (m+1)*(m+1)
= m*(m+1)*(2m+1)/6 + (m+1)*(m+1)
= (m+1)/6*[m*(2m+1) + 6(m+1)]
= (m+1)/6*[2m^2 + m + 6m + 6]
= (m+1)/6*[2m^2 + 7m + 6]
= (m+1)/6*(m+2)*(2m+3)
= (m+1)*(m+2)*(2m+3)/6
= [(m+1)]*[(m+1)+1)]*[2*(m+1)+1]/6
Thus, if the formula is true for n = m, then it is true for n = m+1.
Therefore, since it is true for n =1 it is true for all positive integers.