Shapovalov elements θβ,m of the classical or quantized universal enveloping algebra of a simple Lie algebra g are parameterized by a positive root β and a positive integer m. They relate the highest vector of a reducible Verma module with highest vectors of its submodules. We obtain a factorization of θβ,m to a product of θβ,1 and calculate θβ,1 as a residue of a matrix element of the inverse Shapovalov form via a generalized Nagel-Moshinsky algorithm. This way we explicitly express θβ,m of a classical simple Lie algebra through the Cartan-Weyl basis in g. In the case of quantum groups, we give an analogous formulation through the entries of the R-matrix (quantum L-operator) in fundamental representations.