How to prove that there exist no functions $f,g:\Bbb{R}\to\Bbb{R}$ such that $f(g(x))=x^{2018}$ and $g(f(x))=x^{2019}$?

Here is a simple proof (to avoid confusion I will write $f^{y}(x)$ instead of $f(x)^{y}$):

Suppose that there are two such functions $f,g$ as in your question.

Note that $\forall\space i \in\{-1, 0, 1\}$, we have $f(i^{2019}) = f(i) = f^{2018}(i)$ and thus $\label{*}\tag{*} f(i) \in \{0, 1\} \quad\forall\space i \in\{-1, 0, 1\}.$

On the other hand, since $g(f(x)) = x^{2019} \space\forall x\in\mathbb{R}$,

  • $g(f(1)) = 1$,
  • $g(f(0)) = 0$,
  • $g(f(-1)) = -1$.

This is impossible since $f$ (and thus also $g\circ f$) only takes two (or fewer) values on $\{-1, 0, 1\}$ after \eqref{*}. $\Longrightarrow\Longleftarrow\quad\square$


Another classic trick that can be used here is that there is a bijection between the set of fixed points of $fg$ and fixed points of $gf$. If $x$ is such that $f(g(x))=x$ then $g(f(g(x)))=g(x)$ so $g(x)$ is a fixed point of $gf$. Similarly whenever $y$ is a fixed point of $gf$, we can show that $f(y)$ is a fixed point of $fg$. Convince yourself that on the sets of fixed points, this gives a bijection.

Can you see why the $fg$ and $gf$ you've been given fail this condition?