結果

問題 No.167 N^M mod 10
コンテスト
ユーザー 佐藤淳平
提出日時 2019-09-09 20:09:32
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,169 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 998 ms
コンパイル使用メモリ 192,000 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2026-03-17 10:23:02
合計ジャッジ時間 1,873 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 26 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #
raw source code

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 = 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