Lucas-Lehmer test for Mersenne numbers (Lisp)

From LiteratePrograms

Jump to: navigation, search
Other implementations: Erlang | Haskell | J | Java | Lisp | Python | Ruby | Scheme

This program is a code dump.
Code dumps are articles with little or no documentation or rearrangement of code. Please help to turn it into a literate program. Also make sure that the source of this code does consent to release it under the MIT or public domain license.


(defun lucas-lehmer (p)
    (let ((s 4)
          (M (1- (expt 2 p))))
      (dotimes (i (- p 2))
        (setq s
              (mod (- (* s s) 2) M)))
      (= s 0)))
Download code
Views