Matrix element factorization in the unitary group approach for configuration interaction calculations