結果

問題 No.16 累乗の加算
ユーザー tentententen
提出日時 2020-11-17 08:34:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 137 ms / 5,000 ms
コード長 641 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 72,788 KB
実行使用メモリ 56,132 KB
最終ジャッジ日時 2023-09-30 07:40:54
合計ジャッジ時間 5,187 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,788 KB
testcase_01 AC 126 ms
55,456 KB
testcase_02 AC 137 ms
56,132 KB
testcase_03 AC 130 ms
55,704 KB
testcase_04 AC 132 ms
55,864 KB
testcase_05 AC 133 ms
56,096 KB
testcase_06 AC 135 ms
56,016 KB
testcase_07 AC 132 ms
55,456 KB
testcase_08 AC 134 ms
55,940 KB
testcase_09 AC 134 ms
55,780 KB
testcase_10 AC 136 ms
55,936 KB
testcase_11 AC 125 ms
55,808 KB
testcase_12 AC 136 ms
55,932 KB
testcase_13 AC 137 ms
56,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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