Source: https://www.lamsade.dauphine.fr/~croyer/ensdocs/Exos-Cpp.pdf