The "factor-exp-list" function calculates the list of exponents of the factorization of the number x:
Code: Select all
(define (factor-exp-list x)
(if (= x 1) '(1)
(letn (fattori (factor x)
unici (unique fattori))
(count unici fattori))))
1000 = 2^3 * 5^3
(factor-exp-list 1000)
;-> (3 3)
Code: Select all
(define (checkpower n)
(if (> (setq a (apply gcd (factor-exp-list n))) 1)
(list (ceil (pow n (div 1 a))) a)
nil)))
(checkpower (pow 3 12))
;-> (3 12)
(checkpower (pow 4 25))
;-> (2 50)
(checkpower (+ (pow 3 7) 1))
;-> nil