An accurate and robust geometrically exact beam formulation (GEBF) is developed to simulate the dynamics of a beam with large deformations and large rotations. The undeformed configuration of the centroid line of the beam can be either straight or curved, and cross sections of the beam can be either uniform or nonuniform with arbitrary shapes. The beam is described by the position of the centroid line and a local frame of a cross section, and a rotation vector is used to characterize the rotation of the cross section. The elastic potential energy of the beam is derived using continuum mechanics with the small-strain assumption and linear constitutive relation, and a factor naturally arises in the elastic potential energy, which can resolve a drawback of the traditional GEBF. Shape functions of the position vector and rotation vector are carefully chosen, and numerical incompatibility due to independent discretization of the position vector and rotation vector is resolved, which can avoid the shear locking problem. Numerical singularity of the rotation vector with its norm equal to zero is eliminated by Taylor polynomials. A rescaling strategy is adopted to resolve the singularity problem with its norm equal to $2m\pi $, where m is a nonzero integer. The current formulation can be used to handle linear and nonlinear dynamics of beams under arbitrary concentrated and distributed loads. Several benchmark problems are simulated using the current formulation to validate its accuracy, adaptiveness, and robustness.