Completing the square and long division