Source: http://math.unice.fr/~lemahieu/1718feuillesTD4algarithm1.pdf