Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- another b q = case (mod q b) of
- 0 -> another b (div q b)
- _ -> q
- cycled b q = case b of
- 1 -> (b, q)
- _ -> let nq = another b q in cycled (gcd nq b) nq
- answer p q b = let g = gcd p q in
- let q2 = div q g in
- let b2 = gcd q2 b in
- let (fb, fq) = cycled b2 q2 in
- case fq of
- 1 -> "Finite"
- _ -> "Infinite"
- doTest n list = if n > 0 && length list > 2
- then let p:q:b:xlist = list in (answer p q b):(doTest (n - 1) xlist)
- else []
- doAll inp = let q = map read inp in
- case q of
- [] -> []
- x:xs -> doTest x xs
- main = interact $ unlines . doAll . words
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement