Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,15 @@
powerMod
:: (Integral a, Integral b)
=> a -> a -> b -> a
powerMod m _ 0 = 1
powerMod m x n
| n > 0 = f x_ (n - 1) x_
where
x_ = x `rem` m
f _ 0 y = y
f a d y = g a d
where
g b i
| even i = g (b * b `rem` m) (i `quot` 2)
| otherwise = f b (i - 1) (b * y `rem` m)
powerMod m _ _ = error "powerMod: negative exponent"

View file

@ -0,0 +1,17 @@
import Data.List (foldl1') --'
foldl1_ = foldl1' --'
multOrder a m
| gcd a m /= 1 = error "Arguments not coprime"
| otherwise = foldl1_ lcm $ map (multOrder_ a) $ primeFacsExp m
multOrder_ a (p, k) = r
where
pk = p ^ k
t = (p - 1) * p ^ (k - 1) -- totient \Phi(p^k)
r = product $ map find_qd $ primeFacsExp t
find_qd (q, e) = q ^ d
where
x = powerMod pk a (t `div` (q ^ e))
d = length $ takeWhile (/= 1) $ iterate (\y -> powerMod pk y q) x