• + 2 comments

    Haskell

    import Data.List (intercalate)
    
    gcdl :: [Int] -> [Int] -> [Int]
    gcdl [] xs = []
    gcdl xs [] = []
    gcdl xs@(x : xe : xtail) ys@(y : ye : ytail)
      | x < y = gcdl xtail ys
      | x > y = gcdl xs ytail
      | otherwise = x : min xe ye : gcdl xtail ytail
    
    main = do
      contents <- getContents
      let xss = [map read $ words l | l <- tail $ lines contents]
      putStrLn $ intercalate " " $ map show $ foldl1 gcdl xss