結果

問題 No.167 N^M mod 10
ユーザー くわいくわい
提出日時 2015-11-21 16:05:00
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 778 ms / 1,000 ms
コード長 438 bytes
コンパイル時間 10,668 ms
コンパイル使用メモリ 260,688 KB
実行使用メモリ 64,324 KB
最終ジャッジ日時 2024-04-30 13:44:23
合計ジャッジ時間 32,540 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 767 ms
64,164 KB
testcase_01 AC 752 ms
64,284 KB
testcase_02 AC 756 ms
64,180 KB
testcase_03 AC 753 ms
64,280 KB
testcase_04 AC 756 ms
64,256 KB
testcase_05 AC 760 ms
64,324 KB
testcase_06 AC 767 ms
64,296 KB
testcase_07 AC 752 ms
64,244 KB
testcase_08 AC 759 ms
64,264 KB
testcase_09 AC 750 ms
64,208 KB
testcase_10 AC 747 ms
64,204 KB
testcase_11 AC 750 ms
64,292 KB
testcase_12 AC 747 ms
64,256 KB
testcase_13 AC 747 ms
64,168 KB
testcase_14 AC 737 ms
64,252 KB
testcase_15 AC 768 ms
64,192 KB
testcase_16 AC 760 ms
64,144 KB
testcase_17 AC 750 ms
64,284 KB
testcase_18 AC 746 ms
64,200 KB
testcase_19 AC 755 ms
64,172 KB
testcase_20 AC 757 ms
64,072 KB
testcase_21 AC 778 ms
64,060 KB
testcase_22 AC 758 ms
64,012 KB
testcase_23 AC 743 ms
64,312 KB
testcase_24 AC 760 ms
64,244 KB
testcase_25 AC 745 ms
64,012 KB
testcase_26 AC 762 ms
64,104 KB
testcase_27 AC 763 ms
64,276 KB
testcase_28 AC 748 ms
64,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.io.StdIn

object Problem167 {

  def proc(N: String, M: String): Int = {
    if (M.length == 1 && M.toInt == 0) return 1

    val a = N.last.asDigit
    val b = M.takeRight(2).toInt % 4 match {
      case 0 => 4
      case x => x
    }
    Math.pow(a, b).toInt % 10
  }

  def main(args: Array[String]) = {
    val N = StdIn.readLine()
    val M = StdIn.readLine()

    val result: Int = proc(N, M)
    println(result)
  }
}
0