結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
Ysmr_Ry
|
| 提出日時 | 2014-11-29 23:00:05 |
| 言語 | Haskell (9.10.1) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 686 bytes |
| コンパイル時間 | 1,584 ms |
| コンパイル使用メモリ | 170,752 KB |
| 実行使用メモリ | 63,644 KB |
| 最終ジャッジ日時 | 2024-06-11 07:25:22 |
| 合計ジャッジ時間 | 8,775 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 WA * 1 TLE * 1 -- * 5 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main ( Main.hs, Main.o )
Main.hs:8:11: warning: [GHC-63394] [-Wx-partial]
In the use of ‘head’
(imported from Prelude, but defined in GHC.List):
"This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
|
8 | else [head $ dropWhile (=='0') $ reverse $ n`divL`m]
| ^^^^
[2 of 2] Linking a.out
ソースコード
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
Ysmr_Ry