(* ------------------ First Version ------------------ *) (* Check to see if the two inputs are relatively prime * Return 1 if they are relative prime, otherwise return 0 *) let is_prime x y = let ret = ref 1 in let i = ref 2 in let cond = min x y in while (!i <= cond) do if (((x mod !i) = 0) && ((y mod !i) = 0)) then (ret := 0; i:= x + 1) else i := !i + 1 done; !ret (* ------------------ Second Version ------------------ *) (* Using Euclidean algorithm to determine * the greatest common divisor (GCD) of * two elements of any integers *) let gcd x y = let a = ref x in let b = ref y in let c = ref 0 in while (!b <> 0) do c := !a; a := !b; b := !c mod !b done; !a (* Check to see if the two inputs are relatively prime * Return 1 if they are relative prime, otherwise return 0 *) let is_prime_super x y = if (gcd x y == 1) then 1 else 0 (* Return the number of positive numbers <= n * that are relatively prime to n *) let euler n = let ret = ref 1 in for i = 2 to (abs n)-1 do ret := !ret + (is_prime_super i (abs n)) done; !ret