Euclid's algorithm finding the greatest common divider (gcd) and the least common multiple (lcm) of two integers. ?- gcd(6,15,X). X = 3 ?- lcm(6,7,Y). Y = 42 ?- lcm(16,14,R). R = 112
gcd(X,0,X). gcd(X,Y,D):- R is X mod Y, gcd(Y,R,D). lcm(X,Y,M):- gcd(X,Y,D),M is (X*Y)/D.