summaryrefslogtreecommitdiff
path: root/31-41/34.hs
blob: fe542a255acae5f35f407255cc5303ce38b246cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
import Data.List (foldl')

myGCD :: Int -> Int -> Int


myGCD a 0 = abs a
myGCD a b = myGCD b (a `mod` b)

totient :: Int -> Int

totient x = foldl' (\acc y -> acc + if myGCD x y == 1 then 1 else 0) 0 [1..x]