I do not think this is a trick because it is a way to solve exact differential equations. Suppose we are given an exact differential equation
$$M(x, y)dx + N(x, y)dy = 0$$
whose solution is the family $f(x, y) = \text{const.}$ You probably know that if $f(x, y)$ has continuous second partials, then
$$\frac{\partial^2 f}{\partial x \partial y} = \frac{\partial^2 f}{\partial y \partial x}.$$
Now, if
$$\frac{\partial f}{\partial x} = M$$
and
$$\frac{\partial f}{\partial y} = N,$$
then
$$\frac{\partial M}{\partial y} = \frac{\partial N}{\partial x}.$$
This allows us to test exactness. One way to find $f(x, y)$ is to integrate $M$ w.r.t. $x$ and $N$ w.r.t. $y$. Then we need to add an arbitrary function of $y$ to the first integral and an arbitrary function of $x$ to the second. Then we can "merge" the equations as you mentioned. For example, suppose
$$\int M(x, y)dx = x - x^2 y + Y(y)$$
and
$$\int N(x, y)dy = y^4 - x^2 y + X(x).$$
We see that $\partial f/\partial x = M$ and $\partial f/\partial y = N$, and
$$f(x, y) = x - x^2 y + y^4.$$
As a result,
$$x - x^2 y + y^4 = \text{const.}$$
Hope this helps.
$ydx+xdy=0 \tag 1$
$M=y$ and $N=x$ and $\frac{\partial M}{\partial y}=\frac{\partial
N}{\partial x}=1$, so Eq.$(1)$ is exact.
$\frac{y}{x}dx+dy=0 \tag 2$
$M=\frac{y}{x}$ and $N=1.$ Therefore $\frac{\partial M}{\partial
y}=\frac{1}{x}$ and $\frac{\partial N}{\partial x}=0$, so Eq.$(2)$ is not exact.
To make exact Eq.$(2)$, one have to multiply it by an integrating factor which is $x$ in this case :
$x\left(\frac{y}{x}dx+dy=0\right)=ydx+xdy=0$
Now, the equation is exact.
Of course, $(1)$ and $(2)$ are related to a same equation $(3)$ :
$\frac{dy}{dx}=-\frac{y}{x} \tag 3$
But don't confuse $(1)$ , $(2)$ and $(3)$. They are not identical equations. They are related by multiplying them by factors. It is normal that one of them is an exact differential and the others not exact differential.
The purpose of the game is to find a convenient factor called "integrating factor" such as a given non exact ODE becomes a different ODE which is then an exact ODE.
SECOND EXAMPLE :
$(y^2\arctan(y)+y^2x+\arctan(y)+x)dx+(x+y)dy=0 \tag 4$
The integrating factor is $\frac{1}{1+y^2}$.
If one multiply Eq.$(4)$ by $\frac{1}{1+y^2}$ he obtains after simplification :
$(x+\arctan(y))dx+\frac{x+y}{1+y^2}dy=0 \tag 5$
which is exact.
Best Answer
Here is a rule which almost always works: (You can differentiate the solution to check). Integrate $M$ with respect to $x$ keeping $y$ as a constant and integrate only those terms of $N$ which do not involve $x$ with respect to $y$. Sum the result and equate to a constant.
So as $\displaystyle\int_{y\mbox{ constant}}Mdx=\int(5x+4y)dx=\frac{5x^2}{2}+4xy$, and $\displaystyle\int\mbox{(Terms of $N$ free of $x$) } dy=-8\int y^3dy=-2y^4$ we have $\frac{5x^2}{2}+4xy-2y^4=c$ as the solution.