1.2.0 permalink Arrow_down_16x16
  • (lcm a b)
(lcm a b) returns the least common multiple of a and b

1 Example top

  • user=> (lcm 2 3)
    6
    
    user=> (lcm 2 4)
    4
    
    user=> (reduce lcm [2 3 4 5])
    60
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/math.clj:169 top

(defn lcm
  "(lcm a b) returns the least common multiple of a and b"
  [a b]
  (when (or (not (integer? a)) (not (integer? b)))
    (throw (IllegalArgumentException. "lcm requires two integers")))
  (cond (zero? a) 0
        (zero? b) 0
        :else (abs (* b (quot a (gcd a b))))))
Vars in clojure.contrib.math/lcm: * cond defn integer? not or quot when zero?
Used in 0 other vars

Comments top

No comments for lcm. Log in to add a comment.