Greatest Common Multiple

Using Euclid's Algorithm, we find the GCM.

Runs extremely quickly, can likely be considered constant time. Very useful for reducing fractions.

Java
long P = input.nextLong ; long Q = input.nextLong ; long rem = -1 ; long divisor = P ; long dividend = Q ; if (P != 0) {    while (rem != 0) {        rem = dividend - (dividend/divisor) * divisor ; dividend = divisor ; if (rem != 0) divisor = rem ; }    P /= divisor ; Q /= divisor ; }