Advertisement
Guest User

A full

a guest
Jun 14th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module First where
  2.  
  3. another :: Int -> Int -> Int
  4. another b q = case (mod q b) of
  5.               0 -> another b (div q b)
  6.               _ -> q
  7.  
  8. cycled :: Int -> Int -> (Int, Int)
  9. cycled b q = case b of
  10.             1 -> (b, q)
  11.             _ -> let nq = another b q in cycled (gcd nq b) nq
  12.  
  13. answer :: Int -> Int -> Int -> String
  14. answer p q b = let g = gcd p q in
  15.                let q2 = div q g in
  16.                let b2 = gcd q2 b in
  17.                let (fb, fq) = cycled b2 q2 in
  18.                case fq of
  19.                1 -> "Finite"
  20.                _ -> "Infinite"
  21.  
  22.  
  23. doTest :: Int -> [Int] -> [String]
  24. doTest n list = if n > 0 && length list > 2
  25.                 then let p:q:b:xlist = list in (answer p q b):(doTest (n - 1) xlist)
  26.                 else []
  27.  
  28. doAll :: [String] -> [String]
  29. doAll inp = let q = map read inp in
  30.     case q of
  31.     [] -> []
  32.     x:xs -> doTest x xs
  33.  
  34. main :: IO ()
  35. main = interact $ unlines . doAll . words
  36. --main = print (unlines $ doAll $ words "1 5 6 10")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement