結果

問題 No.167 N^M mod 10
ユーザー はむ吉🐹はむ吉🐹
提出日時 2015-10-26 19:18:56
言語 Haskell
(9.8.2)
結果
AC  
実行時間 103 ms / 1,000 ms
コード長 330 bytes
コンパイル時間 6,676 ms
コンパイル使用メモリ 164,320 KB
実行使用メモリ 18,984 KB
最終ジャッジ日時 2023-10-21 23:55:54
合計ジャッジ時間 9,133 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,260 KB
testcase_01 AC 2 ms
5,268 KB
testcase_02 AC 93 ms
18,440 KB
testcase_03 AC 93 ms
18,440 KB
testcase_04 AC 92 ms
18,440 KB
testcase_05 AC 2 ms
5,260 KB
testcase_06 AC 3 ms
5,256 KB
testcase_07 AC 2 ms
5,244 KB
testcase_08 AC 2 ms
5,248 KB
testcase_09 AC 2 ms
5,256 KB
testcase_10 AC 2 ms
5,244 KB
testcase_11 AC 3 ms
5,248 KB
testcase_12 AC 2 ms
5,244 KB
testcase_13 AC 2 ms
5,248 KB
testcase_14 AC 2 ms
5,116 KB
testcase_15 AC 2 ms
5,256 KB
testcase_16 AC 2 ms
5,256 KB
testcase_17 AC 3 ms
5,260 KB
testcase_18 AC 2 ms
5,264 KB
testcase_19 AC 2 ms
5,268 KB
testcase_20 AC 2 ms
5,348 KB
testcase_21 AC 2 ms
5,388 KB
testcase_22 AC 92 ms
18,440 KB
testcase_23 AC 92 ms
18,440 KB
testcase_24 AC 103 ms
18,984 KB
testcase_25 AC 93 ms
18,440 KB
testcase_26 AC 4 ms
6,800 KB
testcase_27 AC 83 ms
17,416 KB
testcase_28 AC 83 ms
17,416 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

modexp :: Integral a => a -> a -> a -> a
modexp b ex m
    | ex == 0   = 1
    | even ex   = flip mod m $ (\x -> x * x) $ flip mod m $ modexp b (div ex 2) m 
    | otherwise = flip mod m $ mod b m * (flip mod m $ modexp b (ex - 1) m)

main :: IO ()
main = print . (\(n : m : _) -> modexp n m 10) .map read . words =<< getContents
0