素数 prolog lisp编写

素数 prolog lisp编写

  isPrime(N, Answer)

  Given an integer N >= 2:
    Answer = prime               iff  N is prime
    Answer = composite(Factors)  iff  N is composite, with *prime* factors Factors

  Examples:
    ?- isPrime(11, Answer).
    Answer = prime
    ?- isPrime(20, Answer).
    Answer = composite([2, 5])     % The factors of 20 are: 2, 4, 5, 10.
                                   % The *prime* factors of 20 are: 2, 5.

   Replace the word "change_this" in the rules below.
   
   Hint: You should return the *prime* factors (not all of the factors),
         but it may be useful to first write a version of isPrime
           that returns all of the factors,
         complete question Q2b,
         and then return to this question.

你可能感兴趣的:(prolog,lisp,lisp,prolog)