Solution (source code)

= Solution

A <differential one-form> $P\,dx+Q\,dy$ is an <exact differential> if there is a differentiable <function> $F$ with $P=F_x$ and $Q=F_y$, so the form equals $dF$. For continuously differentiable $P,Q$, equality of mixed <partial derivatives> gives the necessary condition
$$
\boxed{P_y=Q_x.}
$$
A local differential condition need not by itself give a global potential on a domain with holes; no such issue arises for the explicit primitives here.

For the first form, $P_y=2y=Q_x$ and direct differentiation gives
$$
\boxed{y^2\,dx+2xy\,dy=d(xy^2).}
$$
For the second, $P_y=2y$ but $Q_x=y^2$. These are not equal on any nonempty open subset of the plane, so that form is not an <exact differential>. Nevertheless,
$$
y^2\,dx+xy^2\,dy=y^2(dx+x\,dy)
=\boxed{y^2e^{-y}\,d(xe^y)}.
$$
Thus one suitable pair is $f(x,y)=xe^y$, $g(y)=y^2e^{-y}$. This factorization is smooth even at $y=0$. On regions where $y\ne0$, its reciprocal factor $e^y/y^2$ is an <integrating factor> which turns the original form into $df$.