結果

問題 No.167 N^M mod 10
ユーザー 佐藤淳平佐藤淳平
提出日時 2019-09-09 20:10:27
言語 Haskell
(9.8.2)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 1,169 bytes
コンパイル時間 4,331 ms
コンパイル使用メモリ 174,848 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-04-27 02:55:58
合計ジャッジ時間 3,270 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 5 ms
7,552 KB
testcase_03 AC 5 ms
7,680 KB
testcase_04 AC 5 ms
7,040 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 5 ms
7,808 KB
testcase_23 AC 5 ms
7,680 KB
testcase_24 AC 5 ms
7,296 KB
testcase_25 AC 6 ms
7,552 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 5 ms
7,680 KB
testcase_28 AC 5 ms
7,040 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 Data.Char (digitToInt)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = interact $ show . solve . words

solve :: [String] -> Int
solve [s, t]
    | t == "0" = 1
    | n == 0   = 0
    | n == 1   = 1
    | n == 2   = if i `mod` 4 == 1 then 2 else if i `mod` 4 == 2 then 4 else if i `mod` 4 == 3 then 8 else 6
    | n == 3   = if i `mod` 4 == 1 then 3 else if i `mod` 4 == 2 then 9 else if i `mod` 4 == 3 then 7 else 1
    | n == 4   = if m `mod` 2 == 0 then 6 else 4
    | n == 5   = 5
    | n == 6   = 6
    | n == 7   = if i `mod` 4 == 1 then 7 else if i `mod` 4 == 2 then 9 else if i `mod` 4 == 3 then 3 else 1
    | n == 8   = if i `mod` 4 == 1 then 8 else if i `mod` 4 == 2 then 4 else if i `mod` 4 == 3 then 2 else 6
    | n == 9   = if m `mod` 2 == 0 then 1 else 9
    | otherwise = error ""
    where
        n = if (length s) <= 1 then (read :: String -> Int) s else digitToInt $ last s
        m = if (length t) <= 1 then (read :: String -> Int) t else digitToInt $ last t
        i = if (length t) <= 1 then (read :: String -> Int) t else (read :: String -> Int) ([last $ init t] ++ [last t])
0