Calculate the greatest common divisor in R