結果

問題 No.25 有限小数
ユーザー Ysmr_RyYsmr_Ry
提出日時 2014-11-29 23:00:05
言語 Haskell
(9.8.2)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 686 bytes
コンパイル時間 935 ms
コンパイル使用メモリ 159,616 KB
実行使用メモリ 62,020 KB
最終ジャッジ日時 2023-09-02 00:55:27
合計ジャッジ時間 8,233 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,952 KB
testcase_01 AC 3 ms
6,900 KB
testcase_02 AC 3 ms
6,936 KB
testcase_03 AC 2 ms
6,956 KB
testcase_04 AC 3 ms
7,024 KB
testcase_05 AC 3 ms
6,952 KB
testcase_06 AC 2 ms
6,956 KB
testcase_07 AC 2 ms
6,928 KB
testcase_08 AC 3 ms
7,008 KB
testcase_09 AC 3 ms
7,016 KB
testcase_10 AC 3 ms
7,048 KB
testcase_11 AC 2 ms
7,024 KB
testcase_12 AC 2 ms
6,976 KB
testcase_13 AC 3 ms
6,928 KB
testcase_14 AC 3 ms
6,932 KB
testcase_15 AC 2 ms
6,964 KB
testcase_16 AC 2 ms
6,980 KB
testcase_17 AC 2 ms
7,428 KB
testcase_18 AC 2 ms
6,960 KB
testcase_19 AC 2 ms
7,012 KB
testcase_20 AC 2 ms
7,036 KB
testcase_21 AC 2 ms
7,044 KB
testcase_22 WA -
testcase_23 AC 3 ms
7,148 KB
testcase_24 AC 3 ms
7,068 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

main :: IO ()
main = do
  n <- readLn :: IO Integer
  m <- readLn :: IO Integer

  putStrLn $ if any (\x -> x/=2&&x/=5) $ factor m primes
    then "-1"
    else [head $ dropWhile (=='0') $ reverse $ n`divL`m]

primes :: [Integer]
primes = 2:sieve [3] [3,5..]
  where
    sieve (x:xs) ys = let
        (ps, qs) = span (<x^2) ys
      in ps ++ sieve (xs++ps) (filter ((/=0).(`mod`x)) qs)

factor :: Integer -> [Integer] -> [Integer]
factor n pss@(p:ps)
  | p*p>n        = [n]
  | n`mod`p == 0 = p:factor (n`div`p) pss
  | otherwise    = factor n ps

divL :: Integer -> Integer -> String
divL n m
  | n == 0 = ""
  | otherwise = show (n`div`m)++divL (n`mod`m*10) m
0