結果

問題 No.16 累乗の加算
ユーザー sekiya9311sekiya9311
提出日時 2016-10-19 21:06:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 138 ms / 5,000 ms
コード長 584 bytes
コンパイル時間 1,991 ms
コンパイル使用メモリ 72,000 KB
実行使用メモリ 56,148 KB
最終ジャッジ日時 2023-09-08 12:02:22
合計ジャッジ時間 4,790 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,488 KB
testcase_01 AC 126 ms
56,148 KB
testcase_02 AC 135 ms
55,500 KB
testcase_03 AC 130 ms
55,720 KB
testcase_04 AC 131 ms
55,528 KB
testcase_05 AC 132 ms
56,112 KB
testcase_06 AC 133 ms
55,680 KB
testcase_07 AC 136 ms
55,636 KB
testcase_08 AC 136 ms
55,572 KB
testcase_09 AC 135 ms
55,312 KB
testcase_10 AC 136 ms
55,648 KB
testcase_11 AC 126 ms
55,656 KB
testcase_12 AC 136 ms
55,532 KB
testcase_13 AC 138 ms
55,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  static Scanner sc;
  final static int MOD = 1000003;
  static long pow_mod(long a, long p) {
    if (p == 0) return 1;
    if (p % 2 == 1) return a * pow_mod(a, p - 1) % MOD;
    long t = pow_mod(a, p / 2);
    return t * t % MOD;
  }
  public static void main(String[] args) {
    sc = new Scanner(System.in);
    long ans = 0;
    int x = sc.nextInt();
    int N = sc.nextInt();
    for (int i = 0; i < N; i++) {
      int buf = sc.nextInt();
      ans = (ans + pow_mod(x, buf)) % MOD;
    }
    System.out.println(ans);
    return;
  }
}
0