Legendre's theorem on continued fractions