A theorem of Beltrami and the integration of the geodesic equations