From https://en.wikipedia.org/wiki/Decisional_Diffie%E2%80%93Hellman_assumption:
Importantly, the DDH assumption does not hold in the multiplicative group $\mathbb {Z} _{p}^{*}$, where $p$ is prime. This is because given $g^{a}$ and $g^{b}$, one can efficiently compute the Legendre symbol of $g^{ab}$, giving a successful method to distinguish $g^{ab}$ from a random group element.
The only way I can think of to distinguish $g^c$ from $g^{ab}$ is:
- If $\left(\frac{g}{p}\right)=-1$, then $\left(\frac{g^{ab}}{p}\right) = 1$ if and only if $a$ or $b$ is even (which is $3/4$ of the times).
So if $\left(\frac{g^c}{p}\right) =-1$, probably $g^c\neq g^{ab}$. Nothing is certain.
How'd do you compute $\left(\frac{g^{ab}}{p}\right)$ given $g^a$ and $g^b$?