Let's say we have this integral:
\[\int \sec^n(x) \ dx \]
We can rewrite this as:
\[ \int \sec^{n-2}(x) \sec^2(x) \ dx \]
Now we are going to use integration by parts. Let \(u=\sec^{n-2}(x) \) and \(v = \tan(x) \):
\[ \begin{aligned} u=\sec^{n-2}(x) &\implies du = (n-2) \sec^{n-2}(x)\tan(x) \ dx \\ v = \tan(x) &\implies dv = \sec^2(x) \ dx \end{aligned} \]
Substituting \(u\) and \(v\):
\[uv - \int v \ du = \sec^{n-2}(x)\tan(x) - \int (n-2) \tan^2(x) \sec^{n-2}(x) \ dx \]
Since \(\tan^2(x) = \sec^2(x) - 1\):
\[\sec^{n-2}(x)\tan(x) - \int (n-2) (\sec^2(x) - 1) \sec^{n-2}(x) \ dx \]
Simplifying:
\[\sec^{n-2}(x)\tan(x) - (n-2) \int (\sec^n(x) - \sec^{n-2}(x)) \ dx \]
Now we end up with:
\[\int \sec^n(x) \ dx = \sec^{n-2}(x)\tan(x) - (n-2) \int \sec^n(x) \ dx + (n-2) \int \sec^{n-2}(x) \ dx \]
Rearranging:
\[ (n-1) \int \sec^n(x) \ dx = \sec^{n-2}(x)\tan(x) + (n-2) \int \sec^{n-2}(x) \ dx \]
And this brings us to our last step:
\[ \int \sec^n(x) \ dx = \frac{1}{(n-1)} \sec^{n-2}(x)\tan(x) + \frac{(n-2)}{(n-1)} \int \sec^{n-2}(x) \ dx \]