Data update
This commit is contained in:
parent
8f05c7136f
commit
0bf4da02c3
82 changed files with 2194 additions and 118 deletions
25
Task/Totient-function/Miranda/totient-function.miranda
Normal file
25
Task/Totient-function/Miranda/totient-function.miranda
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
main :: [sys_message]
|
||||
main = [Stdout (lay (map showline [1..25])),
|
||||
Stdout (lay (map countprimes (25:map (10^) [2..5])))]
|
||||
|
||||
countprimes :: num->[char]
|
||||
countprimes n = "There are " ++ show amount ++ " primes up to " ++ show n
|
||||
where amount = #filter prime [2..n]
|
||||
|
||||
showline :: num->[char]
|
||||
showline n = "phi(" ++ show n ++ ") = " ++ show (totient n) ++ ", " ++ kind
|
||||
where kind = "prime", if prime n
|
||||
= "composite", otherwise
|
||||
|
||||
prime :: num->bool
|
||||
prime n = totient n = n - 1
|
||||
|
||||
totient :: num->num
|
||||
totient n = loop n n (2:[3, 5..])
|
||||
where loop tot n (d:ds)
|
||||
= tot, if n<=1
|
||||
= tot - tot div n, if d*d > n
|
||||
= loop tot n ds, if n mod d ~= 0
|
||||
= loop (tot - tot div d) (remfac n d) ds, otherwise
|
||||
remfac n d = n, if n mod d ~= 0
|
||||
= remfac (n div d) d, otherwise
|
||||
Loading…
Add table
Add a link
Reference in a new issue