結果
| 問題 |
No.816 Beautiful tuples
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-19 22:00:03 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,500 ms |
| コード長 | 541 bytes |
| コンパイル時間 | 5,330 ms |
| コンパイル使用メモリ | 170,752 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-22 19:12:41 |
| 合計ジャッジ時間 | 5,825 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
import Control.Applicative
main :: IO ()
main = solve <$> f >>= print
where
f = map read <$> words <$> getLine
solve :: [Int] -> Int
solve [a, b] = f . divs $ a + b
where
f [] = -1
f (c:cs)
| a /= c && b /= c && (a + c) `mod` b == 0 && (b + c) `mod` a == 0 = c
| otherwise = f cs
divs :: Int -> [Int]
divs n = let (xs, ys) = f [] [] 1
in xs ++ ys
where
f as bs x
| x ^ 2 > n = (reverse as, bs)
| n `mod` x == 0 = f (x:as) (n `div` x :bs) (x + 1)
| otherwise = f as bs (x + 1)