Source: http://www.enseignement.polytechnique.fr/informatique/INF412/uploads/Main/pc9-solution.pdf