結果

問題 No.167 N^M mod 10
ユーザー 佐藤淳平佐藤淳平
提出日時 2019-09-09 20:05:27
言語 Haskell
(9.8.2)
結果
RE  
実行時間 -
コード長 1,004 bytes
コンパイル時間 7,757 ms
コンパイル使用メモリ 162,244 KB
実行使用メモリ 10,932 KB
最終ジャッジ日時 2023-09-10 23:36:40
合計ジャッジ時間 9,558 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,864 KB
testcase_01 AC 3 ms
6,720 KB
testcase_02 AC 7 ms
10,884 KB
testcase_03 AC 6 ms
10,856 KB
testcase_04 AC 6 ms
9,940 KB
testcase_05 AC 3 ms
6,692 KB
testcase_06 AC 3 ms
6,720 KB
testcase_07 AC 2 ms
6,636 KB
testcase_08 AC 3 ms
6,988 KB
testcase_09 AC 3 ms
6,664 KB
testcase_10 RE -
testcase_11 AC 3 ms
6,968 KB
testcase_12 RE -
testcase_13 AC 2 ms
6,988 KB
testcase_14 WA -
testcase_15 AC 2 ms
6,656 KB
testcase_16 AC 3 ms
6,736 KB
testcase_17 AC 3 ms
6,668 KB
testcase_18 AC 3 ms
7,052 KB
testcase_19 AC 3 ms
7,004 KB
testcase_20 AC 3 ms
7,048 KB
testcase_21 AC 3 ms
6,648 KB
testcase_22 AC 6 ms
10,932 KB
testcase_23 AC 6 ms
10,852 KB
testcase_24 AC 7 ms
10,060 KB
testcase_25 AC 7 ms
10,816 KB
testcase_26 AC 4 ms
8,404 KB
testcase_27 AC 6 ms
10,852 KB
testcase_28 AC 6 ms
10,016 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 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]
    | n == 0   = 0
    | t == "0" = 1
    | 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 = digitToInt $ last s
        m = digitToInt $ last t
        i = (read :: String -> Int) ([last $ init t] ++ [last t])
0