Jump to content

Pisano period: Difference between revisions

m
→‎{{header|Haskell}}: Perhaps a few more (if-then-else) -> guards + pattern matching ? (OP may prefer to revert)
m (→‎{{header|Haskell}}: Perhaps a few more (if-then-else) -> guards + pattern matching ? (OP may prefer to revert))
Line 396:
| 1 == abs m = 0
powMod m p k
| 1 == abs p = mod v m
where
if 1 == p || even k
then mod 1 mv
else| mod1 == p m|| even k = 1
| otherwise = p
powMod m p k = go p k
where
Line 405 ⟶ 406:
go _ 0 = 1
go u 1 = mod u m
go u i =
let| weven i = goto uw (quot i 2)w
in| ifotherwise even= ito u (to w w)
then to w wwhere
w = else togo u (toquot wi w2)
 
-- Fermat primality test
Line 415 ⟶ 416:
:: Integral a
=> a -> Bool
probablyPrime p =
if| p < 2 || even p = 2 == p
| otherwise then= 21 == powMod p 2 (p - 1)
else 1 == powMod p 2 (p - 1)
 
primes
Line 457:
factor n = go n primes
where
fun x d c =
if| 0 /= rem x d = (x, c)
| otherwise then= fun (quot x, d) d (succ c)
else fun (quot x d) d (succ c)
go 1 _ = []
go _ [] = []
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.