結果

問題 No.443 GCD of Permutation
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-11-13 22:34:27
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 653 bytes
コンパイル時間 14,988 ms
コンパイル使用メモリ 164,368 KB
実行使用メモリ 11,752 KB
最終ジャッジ日時 2023-08-17 04:27:03
合計ジャッジ時間 16,180 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,372 KB
testcase_01 AC 3 ms
7,152 KB
testcase_02 AC 3 ms
7,160 KB
testcase_03 AC 2 ms
7,176 KB
testcase_04 AC 3 ms
7,284 KB
testcase_05 AC 3 ms
7,000 KB
testcase_06 AC 3 ms
7,196 KB
testcase_07 AC 3 ms
7,268 KB
testcase_08 AC 3 ms
7,396 KB
testcase_09 AC 3 ms
7,368 KB
testcase_10 AC 3 ms
7,124 KB
testcase_11 AC 3 ms
7,360 KB
testcase_12 AC 3 ms
7,276 KB
testcase_13 AC 3 ms
7,096 KB
testcase_14 AC 12 ms
11,752 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

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
0