June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
26
Task/Multiplicative-order/Clojure/multiplicative-order.clj
Normal file
26
Task/Multiplicative-order/Clojure/multiplicative-order.clj
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
(defn gcd [a b]
|
||||
(if (zero? b)
|
||||
a
|
||||
(recur b (mod a b))))
|
||||
|
||||
(defn lcm [a b]
|
||||
(/ (* a b) (gcd a b)))
|
||||
|
||||
(def NaN (Math/log -1))
|
||||
|
||||
(defn ord' [a [p e]]
|
||||
(let [m (imath/expt p e)
|
||||
t (* (quot m p) (dec p))]
|
||||
(loop [dv (factor/divisors t)]
|
||||
(let [d (first dv)]
|
||||
(if (= (mmath/expm a d m) 1)
|
||||
d
|
||||
(recur (next dv)))))))
|
||||
|
||||
(defn ord [a n]
|
||||
(if (not= (gcd a n) 1)
|
||||
NaN
|
||||
(->>
|
||||
(factor/factorize n)
|
||||
(map (partial ord' a))
|
||||
(reduce lcm))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue