結果

問題 No.16 累乗の加算
コンテスト
ユーザー purple_jwl
提出日時 2016-10-27 11:29:30
言語 Scala(Beta)
(3.8.1)
コンパイル:
scalac _filename_
実行:
java -cp .:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala3-library_3/3.8.1/scala3-library_3-3.8.1.jar:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala-library/3.8.1/scala-library-3.8.1.jar _class_
結果
AC  
実行時間 419 ms / 5,000 ms
コード長 476 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 11,300 ms
コンパイル使用メモリ 272,336 KB
実行使用メモリ 58,876 KB
最終ジャッジ日時 2026-03-09 14:52:59
合計ジャッジ時間 18,177 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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