Not necessarily the best approach, but this works in Clojure
(defn pp? [x]
(let [logx (Math/log x)
range-to #(range 2 (inc %))
power? (fn [m]
(when-let [k (some
#(if (= x (long (Math/pow m %))) %)
(range-to (/ logx (Math/log m))))]
(some power? (range-to (Math/sqrt x)))))
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.