I'm interested in finding the constraints on constants $p,\xi$ appearing on a scalar field lagrangian density conformally coupled to spacetime. The transformation is $$ \tilde{g}_{\alpha\beta} = a^2 g_{\alpha\beta},\quad \tilde{\phi} = a^{2p} \phi $$ and I should show that the lagrangian density $$ \tilde{\mathscr{L}} = \frac{1}{2} \tilde{g}^{\alpha\beta} \partial_\alpha \tilde{\phi} \partial_\beta \tilde{\phi} - \xi \tilde{R} \tilde{\phi}^2 $$ is equal to $\mathscr{L}$ before the transformation, up to a total divergence.
The problematic part is to express the transformed Ricci scalar $\tilde{R}$ in terms of $R$ before the transformation, and after a day and many mistakes I obtained (in a torsionless $n$-dimensional manifold) $$ \tilde{R} = a^{-2} R + a^{-3} ( 2 - n ) {\Gamma^\alpha}_{\beta\alpha} \partial^\beta a + 2 a^{-3} ( 1 - n ) \partial_\alpha \partial^\alpha a - a^{-4} ( n - 1 ) ( n - 4 ) \partial_\alpha a \partial^\alpha a $$ but first I'm not sure of the result, second is not at all easy to continue and finally demonstrate that $p$ should be equal to $(2-n)/2$ and $\xi$ to $(n-2)/(4(n-1))$ as stated for example in "Quantum Field Theory in Curved Spacetime" by Parker and Toms (pag. 44 in 2009 edition).
Is there any clear way to continue and demonstrate that $\tilde{\mathscr{L}}=\mathscr{L}$ with stated above conditions or is there an available source were the full calculation is shown?