Source: https://cregut.perso.enseeiht.fr/ENS/2012-apad-algo1/algo1-apad-2012-s1-serie2__Algo-F-corrige.pdf