結果

問題 No.16 累乗の加算
ユーザー purple_jwl
提出日時 2016-10-27 11:29:30
言語 Scala(Beta)
(3.6.2)
結果
AC  
実行時間 805 ms / 5,000 ms
コード長 476 bytes
コンパイル時間 11,018 ms
コンパイル使用メモリ 260,244 KB
実行使用メモリ 63,048 KB
最終ジャッジ日時 2024-06-29 19:39:44
合計ジャッジ時間 20,326 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.io.StdIn

object Main {
  def modPow(x: BigInt, n: Int, mod: Int): BigInt = {
    if (n == 0) return 1
    var res = modPow(x * x % mod, n / 2, mod)
    if ((n & 1) == 1) res = res * x % mod
    return res
  }

  def main(args: Array[String]): Unit = {
    val mod = 1000003

    val Array(x, n) = StdIn.readLine().split(' ').map(_.toInt)

    val ans = StdIn.readLine().split(' ').map {
      a => modPow(x, a.toInt, mod)
    }.sum % mod

    println(ans)
  }
}
0