結果

問題 No.167 N^M mod 10
ユーザー gemmarogemmaro
提出日時 2020-05-17 11:07:26
言語 Elixir
(1.16.2)
結果
AC  
実行時間 627 ms / 1,000 ms
コード長 1,256 bytes
コンパイル時間 1,023 ms
コンパイル使用メモリ 55,176 KB
実行使用メモリ 50,152 KB
最終ジャッジ日時 2023-08-30 00:51:30
合計ジャッジ時間 20,747 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 613 ms
49,204 KB
testcase_01 AC 624 ms
49,360 KB
testcase_02 AC 616 ms
49,796 KB
testcase_03 AC 627 ms
49,160 KB
testcase_04 AC 619 ms
49,296 KB
testcase_05 AC 605 ms
49,236 KB
testcase_06 AC 613 ms
49,296 KB
testcase_07 AC 617 ms
49,284 KB
testcase_08 AC 611 ms
49,284 KB
testcase_09 AC 613 ms
49,848 KB
testcase_10 AC 615 ms
50,032 KB
testcase_11 AC 612 ms
49,288 KB
testcase_12 AC 610 ms
49,832 KB
testcase_13 AC 606 ms
49,356 KB
testcase_14 AC 616 ms
49,332 KB
testcase_15 AC 614 ms
49,892 KB
testcase_16 AC 609 ms
49,732 KB
testcase_17 AC 620 ms
49,144 KB
testcase_18 AC 619 ms
49,248 KB
testcase_19 AC 613 ms
49,336 KB
testcase_20 AC 611 ms
49,388 KB
testcase_21 AC 610 ms
49,332 KB
testcase_22 AC 624 ms
50,152 KB
testcase_23 AC 620 ms
49,856 KB
testcase_24 AC 613 ms
49,812 KB
testcase_25 AC 623 ms
49,284 KB
testcase_26 AC 613 ms
49,892 KB
testcase_27 AC 610 ms
49,280 KB
testcase_28 AC 619 ms
49,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

defmodule Main do
  def main do
    n = IO.read(:line) |> String.trim() |> String.last() |> String.to_integer()
    m = IO.read(:line) |> String.trim() |> String.to_integer()
    solve(n, m) |> IO.puts()
  end

  def solve(n, m) do
    cond do
      m == 0 ->
        1

      :else ->
        case n do
          0 ->
            0

          1 ->
            1

          2 ->
            case m |> rem(4) do
              1 -> 2
              2 -> 4
              3 -> 8
              0 -> 6
            end

          3 ->
            case m |> rem(4) do
              1 -> 3
              2 -> 9
              3 -> 7
              0 -> 1
            end

          4 ->
            case m |> rem(2) do
              1 -> 4
              0 -> 6
            end

          5 ->
            5

          6 ->
            6

          7 ->
            case m |> rem(4) do
              1 -> 7
              2 -> 9
              3 -> 3
              0 -> 1
            end

          8 ->
            case m |> rem(4) do
              1 -> 8
              2 -> 4
              3 -> 2
              0 -> 6
            end

          9 ->
            case m |> rem(2) do
              1 -> 9
              0 -> 1
            end
        end
    end
  end
end
0