Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the function FACTORS which returns a list of prime factors of a number

ID: 3861266 • Letter: C

Question

Consider the function FACTORS which returns a list of prime factors of a number (the rem primitive does remainder division): (defun factors (number) (factors-aux number 2)) (defun factors-aux (number1 number2) (cond ((equal number1 1) nil) ((zerop (rem number1 number2)) (cons number2 (factors-aux (/ number1 number2) number2))) (t (factors-aux number1 (+ number2 1))))) FACTORS returns the list of prime factors of a number. For example: * (factors 60) (2 2 3 5) Number 60 has factors 2 2 3 and 5 (60 = 2 * 2 * 3 * 5). Here is a factorization tree for 60: 60 / 2 30 / 2 15 / 3 5 Write a similar function, FACTOR-TREE, that returns a factorization tree, i.e. * (factor-tree 60) (60 2 (30 2 (15 3 5)))

Explanation / Answer

defun primeFact(number)

cond((number modulus 2 equal 0))

display number 2

number equal to number divide by 2

cond ( number 1 equal 3; number 1 less than sqrt(n); number 1 equal to 1 plus 2)

cond ( number rem number1 equal zero)

display number i

number equal number / number 1

if cond number greater than 2

display n

call the main function

give the value of number

call function primeFactors(number)

HERE NUMBER VALUE IS 60

The first step of program checks whether there are any even numbers or not and after step 1 all other prime factors must be odd and the difference should be atleast 2

In step 2 we run a loop and consider the following

1. finding the least prime factor of number 1

2.removing all occurences from number 1 and number by repeatedly dividing number and number 1

3. repeating the 1 and 2 points for divided number and number 1 equal number 1 plus 2 . The points 1 and 2 are repeated till n becomes 1 or prime number

For Example:

FACTOR -TREE

(factors 108)(2 2 3 3 3)