結果

問題 No.219 巨大数の概算
ユーザー tottoripapertottoripaper
提出日時 2018-03-07 20:56:19
言語 Haskell
(9.8.2)
結果
AC  
実行時間 281 ms / 1,500 ms
コード長 983 bytes
コンパイル時間 6,358 ms
コンパイル使用メモリ 172,800 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2024-04-15 01:57:11
合計ジャッジ時間 20,120 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 281 ms
8,704 KB
testcase_01 AC 270 ms
8,832 KB
testcase_02 AC 274 ms
8,960 KB
testcase_03 AC 277 ms
8,832 KB
testcase_04 AC 216 ms
8,832 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 29 ms
8,320 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 29 ms
8,448 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 273 ms
8,704 KB
testcase_11 AC 276 ms
8,704 KB
testcase_12 AC 271 ms
8,704 KB
testcase_13 AC 273 ms
8,832 KB
testcase_14 AC 278 ms
8,704 KB
testcase_15 AC 272 ms
8,704 KB
testcase_16 AC 274 ms
8,960 KB
testcase_17 AC 273 ms
8,960 KB
testcase_18 AC 271 ms
8,832 KB
testcase_19 AC 270 ms
8,960 KB
testcase_20 AC 274 ms
8,704 KB
testcase_21 AC 271 ms
8,960 KB
testcase_22 AC 270 ms
8,960 KB
testcase_23 AC 272 ms
8,704 KB
testcase_24 AC 270 ms
8,960 KB
testcase_25 AC 272 ms
8,704 KB
testcase_26 AC 276 ms
9,088 KB
testcase_27 AC 275 ms
8,704 KB
testcase_28 AC 272 ms
8,960 KB
testcase_29 AC 277 ms
8,832 KB
testcase_30 AC 274 ms
8,704 KB
testcase_31 AC 274 ms
8,960 KB
testcase_32 AC 275 ms
8,960 KB
testcase_33 AC 274 ms
8,832 KB
testcase_34 AC 270 ms
8,960 KB
testcase_35 AC 273 ms
8,832 KB
testcase_36 AC 278 ms
8,960 KB
testcase_37 AC 277 ms
8,832 KB
testcase_38 AC 272 ms
8,832 KB
testcase_39 AC 275 ms
8,704 KB
testcase_40 AC 274 ms
8,832 KB
testcase_41 AC 272 ms
8,960 KB
testcase_42 AC 274 ms
8,960 KB
testcase_43 AC 276 ms
8,832 KB
testcase_44 AC 275 ms
8,832 KB
testcase_45 AC 274 ms
8,704 KB
testcase_46 AC 274 ms
8,832 KB
testcase_47 AC 272 ms
8,832 KB
testcase_48 AC 270 ms
8,960 KB
testcase_49 AC 274 ms
8,704 KB
testcase_50 AC 272 ms
8,704 KB
testcase_51 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

ソースコード

diff #

import           Control.Monad (replicateM)
import           Data.Fixed
import           Text.Printf

data E40 = E40
instance HasResolution E40 where
  resolution _ = 10 ^ 40

type F40 = Fixed E40

(#*) :: (F40, Integer) -> (F40, Integer) -> (F40, Integer)
(a, s) #* (b, t) = let c = a * b
                   in if c < 10.0 then (c, s + t) else (c / 10.0, s + t + 1)

expt :: (F40, Integer) -> Integer -> (F40, Integer)
expt = expt' (1.0, 0)
  where
    expt' b a 0 = b
    expt' b a n
      | n `mod` 2 == 1 = expt' (b #* a) (a #* a) (n `div` 2)
      | otherwise = expt' b (a #* a) (n `div` 2)

toPair :: F40 -> (F40, Integer)
toPair x
  | x < 10.0 = (x, 0)
  | otherwise = let (y, s) = toPair (x / 10)
                in (y, s + 1)

main = do
  n <- readLn
  replicateM n $ do
    [a, b] <- fmap words getLine
    let a' = toPair $ read a
        b' = read b
        (x, y) = expt a' b'
        x' = floor (x * 10) :: Integer
    printf "%d %d %d\n" (x' `div` 10) (x' `mod` 10) y
0