let rec gcd a b =
  if  a = 0 then b
  else if b = 0 then a
  else let r = a mod b in
  if r = 0 then b else gcd b r