import Data.Ratio import Data.Fixed import Data.List import Control.Monad pos :: Integral a => a -> Ratio a -> Ratio a pos t x = ((numerator x) % (t * denominator x)) `mod'` 1 solve :: Integral a => a -> a -> a -> Ratio a solve t1 t2 t3 = t % (t - fromIntegral (head $ findIndices f l)) where t = lcm (lcm t1 t2) t3 l = map (t %) [t, t - 1..1] f x = pos t1 x == pos t2 x && pos t2 x == pos t3 x trim :: String -> String trim = filter (/= ' ') . map (\c -> if c == '%' then '/' else c) main = do [t1, t2, t3] <- replicateM 3 readLn putStrLn $ trim $ show $ solve t1 t2 t3