(define (prime? x) (if (<= x 1) #f (let loop ((t (- x 1))) (if (eq? t 1) #t (and (not (eq? (modulo x t) 0)) (loop (- t 1))))))) (define (prime-factors x) (if (= x 1) '() (let loop ((t x) (c 2)) (cond ((= t 1) '()) ((and (= (modulo t c) 0) (prime? c)) (cons c (loop (quotient t c) 2))) (else (loop t (+ c 1))))))) (define (prime-factors-mult x) (let ((fs (prime-factors x))) (let loop ((e (cdr fs)) (c (car fs)) (n 1)) (cond ((null? e) (list (list c n))) ((eq? (car e) c) (loop (cdr e) c (+ n 1))) (else (cons (list c n) (loop (cdr e) (car e) 1)))))))