結果
| 問題 |
No.219 巨大数の概算
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-09-14 16:11:56 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 105 ms / 1,500 ms |
| コード長 | 820 bytes |
| コンパイル時間 | 6,059 ms |
| コンパイル使用メモリ | 170,624 KB |
| 実行使用メモリ | 20,480 KB |
| 最終ジャッジ日時 | 2024-07-05 18:06:06 |
| 合計ジャッジ時間 | 13,993 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 51 |
コンパイルメッセージ
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
import Control.Monad
main :: IO ()
main = do
n <- readLn
map solve <$> replicateM n f >>= mapM_ putStrLn
where
-- f = readi B.readInt <$> B.getLine
f = map read <$> words <$> getLine
solve :: [Int] -> String
solve [a, b] = unwords . map show $ let x = pow b in [truncate . fst $ x, flip mod 10 . truncate . (* 10) . fst $ x, snd x]
where
pow :: Int -> (Double, Int)
pow 1 = norm (fromIntegral a, 0)
pow n
| even n = let x = pow (n `div` 2) in mul x x
| otherwise = let x = pow (n `div` 2) in mul (mul x x) (pow 1)
mul :: (Double, Int) -> (Double, Int) -> (Double, Int)
mul (x1, y1) (x2, y2) = norm (x1 * x2, y1 + y2)
norm :: (Double, Int) -> (Double, Int)
norm (x, y)
| x < 10.0 = (x, y)
| otherwise = norm (x / 10.0, y+1)