結果
問題 |
No.443 GCD of Permutation
|
ユーザー |
![]() |
提出日時 | 2016-11-13 22:34:27 |
言語 | Haskell (9.10.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 653 bytes |
コンパイル時間 | 5,588 ms |
コンパイル使用メモリ | 172,544 KB |
実行使用メモリ | 114,560 KB |
最終ジャッジ日時 | 2024-11-25 22:03:57 |
合計ジャッジ時間 | 33,593 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 TLE * 13 |
コンパイルメッセージ
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 Data.Char (digitToInt) import Data.List (nub) factors :: Integral a => a -> [a] factors n = [f | f <- [1 .. n], mod n f == 0] numToDigits :: (Integral a, Show a) => a -> [Int] numToDigits = fmap digitToInt . show gcdOfPermutation :: Integer -> Integer gcdOfPermutation n | length (nub ds) == 1 = n | otherwise = maximum $ filter (\f -> mod n f == 0) (factors $ fromIntegral $ foldr1 gcd xs) where ds = numToDigits n xs = [9 * abs (ds !! i - ds !! j) | let m = length ds, i <- [0 .. m - 1], j <- [0 .. i - 1]] main :: IO () main = do n <- readLn :: IO Integer print $ gcdOfPermutation n