An Efficient Method for Solving Equations in Generalized Quaternion and Octonion Algebras