結果
| 問題 | No.167 N^M mod 10 |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2015-09-17 22:08:14 |
| 言語 | Scala(Beta) (3.8.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 742 bytes |
| 記録 | |
| コンパイル時間 | 8,959 ms |
| コンパイル使用メモリ | 260,752 KB |
| 実行使用メモリ | 59,900 KB |
| 最終ジャッジ日時 | 2026-03-09 13:46:24 |
| 合計ジャッジ時間 | 22,120 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 WA * 2 |
ソースコード
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))
}
}
norioc