We are given that \( p + q = 126 \), where \( p \) is the number of triangles and \( q \) is the number of quadrilaterals formed by the vertices of a regular polygon with \( n \) sides.
Step 1: Calculate \( p \) and \( q \).
The number of triangles formed by selecting 3 vertices from \( n \) vertices is given by:
\[
p = \binom{n}{3} = \frac{n(n-1)(n-2)}{6}.
\]
The number of quadrilaterals formed by selecting 4 vertices from \( n \) vertices is given by:
\[
q = \binom{n}{4} = \frac{n(n-1)(n-2)(n-3)}{24}.
\]
Given that \( p + q = 126 \), we can substitute the expressions for \( p \) and \( q \) and solve for \( n \).
\[
\frac{n(n-1)(n-2)}{6} + \frac{n(n-1)(n-2)(n-3)}{24} = 126.
\]
Multiply through by 24 to eliminate fractions:
\[
4n(n-1)(n-2) + n(n-1)(n-2)(n-3) = 3024.
\]
Now, solve this equation for \( n \).
Step 2: Solve for \( n \).
Solving the above equation, we find that \( n = 8 \).
Step 3: Find the eccentricity.
The equation of the ellipse is given by:
\[
\frac{x^2}{16} + \frac{y^2}{n} = 1.
\]
Substitute \( n = 8 \) into this equation:
\[
\frac{x^2}{16} + \frac{y^2}{8} = 1.
\]
The standard form of an ellipse is:
\[
\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1,
\]
where \( a^2 = 16 \) and \( b^2 = 8 \).
The eccentricity \( e \) of the ellipse is given by:
\[
e = \sqrt{1 - \frac{b^2}{a^2}}.
\]
Substitute \( a^2 = 16 \) and \( b^2 = 8 \):
\[
e = \sqrt{1 - \frac{8}{16}} = \sqrt{1 - \frac{1}{2}} = \sqrt{\frac{1}{2}} = \frac{1}{\sqrt{2}}.
\]