I was trying to write some code for the Euler totient function and tried translating a C code snippet that I found. My end result was
;; Euler totient function for positive integers n
(defun totient ( n / result i )
(setq result n)
(setq i 2)
(while (<= (* i i) n)
(if (zerop (rem n i))
(setq result (- result (/ result i)))
)
(while (zerop (rem n i))
(setq n (/ n i))
)
(setq i (1+ i))
)
(if (> n 1)
(setq result (- result (/ result n)))
)
result
)
This seems to work but I was wondering if anyone else has written their own algorithm knowing more of what they are doing than I am.