A solution to a certain differential equation I was looking for the general solution of the differential equation $$nx \frac{dy}{dx} -2y=-kxy^{1-n}$$
This is my method:
I recognize that the differential equation above is a Bernoulli equation with $n = 1-n$ because it has the form $\frac{dy}{dx} + P(x)y = Q(x)y^n.$ Armed with that thought process, I divided the given differential equation by $nx$ to resemble the form $\frac{dy}{dx} + P(x)y = Q(x)y^n.$ It looks like this: $$\frac{dy}{dx} - \left(\frac{2}{nx}\right) y = \frac{ky^{1-n}}{n}$$
I see that $Q(x)= 1.$ Divide again the differential equation above by $y^{1-n}$, so it becomes: $$y^{-(1-n)} \frac{dy}{dx} - \left(\frac{2}{nx}\right) y^{-n} = \frac{k}{n}$$ or $$y^{n-1} \frac{dy}{dx} - \left(\frac{2}{nx}\right) y^{-n} = \frac{k}{n}$$
Let $y^{-n} = z, $ so it becomes $$\frac{1}{1-(n-1)} \frac{dz}{dx} - \left(\frac{2}{nx}\right)z = \frac{k}{n}$$ or $$-\frac{1}{n} \frac{dz}{dx} - \left(\frac{2}{nx}\right)z = \frac{k}{n}$$
The  differential equation above must have the form $\frac{dz}{dx} + P(x)z = Q(x)$ to get its integrating factor $I(x), $ so the differential equation becomes $$ \frac{dz}{dx} + \left(\frac{2}{x}\right)z = -k$$
The integrating factor then is $I(x) = e^{\int P(x)dx} = e^{\int \frac{2n}{x}dx} = e^{\frac{2}{n} lnx} = x^{\frac{2}{n}} $. Multiplying this integrating factor to the differential equation above, it becomes: $$x^{\frac{2}{n}}\frac{dz}{dx} + x^{\frac{2}{n}}\left(\frac{2}{nx}\right)z = -kx^{\frac{2}{n}}$$ or $$x^{\frac{2}{n}}\frac{dz}{dx} + \frac{2}{n} x^{\frac{-n+2}{n}}z = -kx^{\frac{2}{n}}$$
Then, doing this: $$ d \left(x^{\frac{2}{n}} z \right) = -kx^{\frac{2}{n}}$$ Getting the integral of the terms in the equation, we get: $$x^{\frac{2}{n}} z = \frac{-kn}{2+n} x^{\frac{2+n}{2}} +c$$ or $$\frac{x^{\frac{2}{n}}}{y^n}  = \frac{-kn}{2+n} x^{\frac{2+n}{2}} +c$$
Getting the $y^n,$ the solution to the given differential equation is $$y^n = \frac{\frac{-kn}{2+n} x^{\frac{2+n}{n}} + c}{x^{\frac{2}{n}}}$$
The correct general solution of the differential equation $nx \frac{dy}{dx} -2y=-kxy^{1-n}$ written in the book I used is $y^n = kx+cx^2$
Where did I go wrong?

The integrating factor to solve he linear equation
$$
\frac{dz}{dx} + \frac{2}{x}\,z = -k
$$
is incorrect. It should be $x^2$ (there is no $n$ in the equation.)
