結果

問題 No.167 N^M mod 10
ユーザー noriocnorioc
提出日時 2015-09-17 22:08:14
言語 Scala(Beta)
(3.4.0)
結果
WA  
実行時間 -
コード長 742 bytes
コンパイル時間 12,749 ms
コンパイル使用メモリ 257,760 KB
実行使用メモリ 64,712 KB
最終ジャッジ日時 2024-04-26 20:09:28
合計ジャッジ時間 41,574 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 912 ms
64,440 KB
testcase_01 AC 927 ms
64,332 KB
testcase_02 AC 973 ms
64,580 KB
testcase_03 AC 969 ms
64,448 KB
testcase_04 AC 977 ms
64,680 KB
testcase_05 AC 938 ms
64,372 KB
testcase_06 AC 909 ms
64,344 KB
testcase_07 AC 904 ms
64,332 KB
testcase_08 AC 900 ms
64,360 KB
testcase_09 AC 902 ms
64,436 KB
testcase_10 AC 912 ms
64,564 KB
testcase_11 AC 901 ms
64,252 KB
testcase_12 AC 905 ms
64,616 KB
testcase_13 AC 916 ms
64,428 KB
testcase_14 WA -
testcase_15 AC 930 ms
64,420 KB
testcase_16 AC 920 ms
64,196 KB
testcase_17 AC 918 ms
64,428 KB
testcase_18 AC 917 ms
64,332 KB
testcase_19 AC 912 ms
64,384 KB
testcase_20 AC 903 ms
64,580 KB
testcase_21 AC 888 ms
64,480 KB
testcase_22 AC 956 ms
64,504 KB
testcase_23 AC 950 ms
64,584 KB
testcase_24 AC 960 ms
64,388 KB
testcase_25 AC 957 ms
64,712 KB
testcase_26 WA -
testcase_27 AC 971 ms
64,592 KB
testcase_28 AC 966 ms
64,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.collection.mutable.ArrayBuffer

object Main {
  // 1 桁の数字 d を繰り返しかけていったときの
  // d の 1 の位のサイクルを求める
  def calcCycle(d: Int): Array[Int] = {
    assert(0 <= d && d < 10)
    val used = Array.ofDim[Boolean](10)
    val xs = new ArrayBuffer[Int]()
    var x = d
    while (!used(x)) {
      used(x) = true
      xs.append(x)
      x = (x * d) % 10
    }
    xs.toArray
  }

  def main(args: Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val N = sc.nextLine
    val M = sc.nextLine

    val d = N.last - '0'
    val cycle = calcCycle(d)
    val index = (BigInt(M) % cycle.size).toInt
    println(cycle(if (index == 0) cycle.size-1 else index-1))
  }
}
0