Can every smooth scalar function $f$ on $M$ be written as $f=\operatorname{div}(X)$? Let $(M,g)$ be a Riemannian manifold of dimension $n$ and $X$ a vector field over it. divergence of $X$ is a real value function defined by:
$$\operatorname{div}(X)=g(\nabla_{e_i}X,e_i),$$
where $\{e_1,\cdots, e_n\}$ is a local orthonormal frame on $(M,g)$. it also can be defined (see J. M. Lee, p43, Ex. 3.3)
$$\mathcal{L}_XdVol_g=d(i_XdVol_g)=\operatorname{div}(X)dVol_g.$$

Question: Can every smooth scalar function $f$ on $M$ be written as $f=\operatorname{div}(X)$?

I think that this depend on the topology of $M$ by using De-Rham cohomology but I don't know how to apply it. 
 A: Note that you can identify vector fields on $M$ with $(n-1)$-forms. To see this, note that the metric provides a map from $T_pM \to (T_pM)^\ast$ since any non-degenerate symmetric bilinear form provides a map into the dual. Since vector fields are sections of the tangent bundle, we can pointwise take the dual to get a section of the cotangent bundle. However this will be a $1$-form which is not what we want (since taking the exterior derivative of this doesn’t yield what we want). We then apply Hodge duality to convert the $1$-form into an $(n-1)$-form. Taking the divergence more or less amounts to taking the exterior derivative of an $(n-1)$-form to yield an $n$-form. We can play the same trick with Hodge duality to convert this back to a $0$-form i.e. a function. 
Barring all the technical duality, your question can be restated as: is every $n$-form on $M$ exact? Note that $n$-forms on $M$ are trivially closed. So $H_{DR}^n(M)$ can measure whether every function can be written as the divergence of a vector field. In particular, the answer is yes if and only if $H_{DR}^n(M) = 0$. So you can think of this cohomology group as the group of obstructions to solving this PDE. 
Now for an easy criterion: if $M$ is a smooth, connected, oriented manifold, then $H_{DR}^n(M) = \mathbb{R}$ if $M$ is compact and is $0$ if $M$ is not compact. 
