Source: https://www-fourier.ujf-grenoble.fr/~parisse/irem/algolycee.pdf