結果

問題 No.16 累乗の加算
ユーザー purple_jwlpurple_jwl
提出日時 2016-10-27 11:29:30
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 979 ms / 5,000 ms
コード長 476 bytes
コンパイル時間 11,123 ms
コンパイル使用メモリ 268,280 KB
実行使用メモリ 62,588 KB
最終ジャッジ日時 2023-09-12 06:39:03
合計ジャッジ時間 26,656 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 957 ms
62,064 KB
testcase_01 AC 963 ms
62,236 KB
testcase_02 AC 962 ms
62,588 KB
testcase_03 AC 964 ms
62,304 KB
testcase_04 AC 965 ms
62,056 KB
testcase_05 AC 963 ms
62,212 KB
testcase_06 AC 979 ms
61,924 KB
testcase_07 AC 961 ms
61,952 KB
testcase_08 AC 960 ms
61,792 KB
testcase_09 AC 968 ms
61,944 KB
testcase_10 AC 962 ms
62,180 KB
testcase_11 AC 945 ms
62,008 KB
testcase_12 AC 963 ms
61,868 KB
testcase_13 AC 968 ms
62,200 KB
権限があれば一括ダウンロードができます

ソースコード

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