結果

問題 No.16 累乗の加算
ユーザー htensaihtensai
提出日時 2019-12-18 10:58:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,206 bytes
コンパイル時間 3,624 ms
コンパイル使用メモリ 73,620 KB
実行使用メモリ 49,824 KB
最終ジャッジ日時 2023-09-20 06:10:31
合計ジャッジ時間 5,356 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,232 KB
testcase_01 AC 43 ms
49,472 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 46 ms
49,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static final int MOD = 1000003;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first = br.readLine().split(" ", 2);
        long x = Integer.parseInt(first[0]);
        int n = Integer.parseInt(first[1]);
        long[] arr = new long[22];
        long[] base = new long[22];
        arr[0] = 1;
        arr[1] = x;
        base[0] = 1;
        base[1] = 2;
        for (int i = 2; i <= 21; i++) {
            arr[i] = (arr[i - 1] * arr[i - 1]) % MOD;
            base[i] = base[i - 1] * 2;
        }
        String[] line = br.readLine().split(" ", n);
        long ans = 0;
        for (int i = 0; i < n; i++) {
            long a = Integer.parseInt(line[i]);
            long cur = x;
            long y = 1;
            for (int j = 20; j >= 0; j--) {
                if (a / base[j] == 1) {
                    y *= arr[j + 1];
                }
                a %= base[j];            
                y %= MOD;
            }
            ans += y;
            ans %= MOD;
        }
        System.out.println(ans);
    }
}
0