Source: https://www.irif.fr/~francoisl//DIVERS/l3algo-td7cor-0809.pdf