$p_{n+1}=\frac{p_{n}^{2}+a_{n}g_{n}}{2p_{n}},$