結果

問題 No.167 N^M mod 10
ユーザー Michae'GonMichae'Gon
提出日時 2015-07-17 17:16:24
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 662 bytes
コンパイル時間 1,549 ms
コンパイル使用メモリ 164,544 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2023-09-22 16:59:19
合計ジャッジ時間 2,950 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 3 ms
8,408 KB
testcase_04 WA -
testcase_05 AC 3 ms
7,408 KB
testcase_06 WA -
testcase_07 AC 2 ms
7,356 KB
testcase_08 AC 2 ms
7,356 KB
testcase_09 AC 3 ms
7,416 KB
testcase_10 AC 3 ms
7,376 KB
testcase_11 WA -
testcase_12 AC 3 ms
7,420 KB
testcase_13 WA -
testcase_14 AC 2 ms
7,232 KB
testcase_15 AC 2 ms
7,296 KB
testcase_16 AC 3 ms
7,384 KB
testcase_17 AC 3 ms
7,316 KB
testcase_18 WA -
testcase_19 AC 3 ms
7,544 KB
testcase_20 WA -
testcase_21 AC 3 ms
7,584 KB
testcase_22 WA -
testcase_23 AC 3 ms
8,372 KB
testcase_24 AC 4 ms
8,480 KB
testcase_25 WA -
testcase_26 AC 2 ms
7,332 KB
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 qualified Data.ByteString.Char8 as B
import Data.Maybe(fromJust)

main = B.getContents >>= main' . map readInteger' . B.lines
    where
        main' [a, x] = print (pow' a x `mod` m)
{-
        main' [a, x]
            | a == 0 && x == 0 = return ()
            | otherwise = print (pow' a x `mod` m) >> main
-}
m :: Integer
m = 10

readInteger' :: B.ByteString -> Integer
{-# INLINE readInteger' #-}
readInteger' = fst . fromJust . B.readInteger

pow' :: Integer -> Integer -> Integer
pow' a x
    | x == 0 = 1
    | x > m = pow' a (x `mod` m)
    | a > m = pow' (a `mod` m) x
    | even x = pow' (a * a) (x `div` 2)
    | otherwise = a * pow' a (x - 1)
0