list gcd
main = do | |
getLine | |
pss <- read . lines . getContents | |
print $ foldr1 pss | |
-- list of numbers in the form of prime-power pairs | |
-- e.g. 35 would be [5 1 7 1] | |
gcd' _ [] = [] | |
gcd' [] _ = [] | |
gcd' (x0:x1:xs) (y0:y1:ys) = case compare x0 y0 of | |
EQ -> (x0:[ min x1 y1]) : gcd' xs ys | |
LT -> gcd' xs (y0:y1:ys) | |
GT -> gcd' (x0:x1:xs) ys | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment