結果

問題 No.16 累乗の加算
ユーザー yuki2006yuki2006
提出日時 2015-02-09 16:10:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 136 ms / 5,000 ms
コード長 1,230 bytes
コンパイル時間 3,946 ms
コンパイル使用メモリ 74,328 KB
実行使用メモリ 56,180 KB
最終ジャッジ日時 2023-09-08 11:32:49
合計ジャッジ時間 6,622 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,740 KB
testcase_01 AC 125 ms
55,632 KB
testcase_02 AC 136 ms
56,180 KB
testcase_03 AC 129 ms
55,796 KB
testcase_04 AC 130 ms
55,660 KB
testcase_05 AC 132 ms
55,796 KB
testcase_06 AC 134 ms
55,960 KB
testcase_07 AC 133 ms
55,376 KB
testcase_08 AC 133 ms
55,324 KB
testcase_09 AC 134 ms
55,960 KB
testcase_10 AC 135 ms
55,652 KB
testcase_11 AC 126 ms
55,800 KB
testcase_12 AC 133 ms
55,712 KB
testcase_13 AC 131 ms
53,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Yuki016 {
    public static void main(String[] args) {
        Yuki016 p = new Yuki016();

    }

    public Yuki016() {
        Scanner scanner = new Scanner(System.in);
        final int x = scanner.nextInt();
        final int N = scanner.nextInt();
        final int[] a = new int[N];

        int zeroCount = 0;
        final int MOD = 1000003;
        long tmp = x;
        long[] muls = new long[N];
        Arrays.fill(muls, 1);

        long ans2=1;
        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt();
            if (a[i] == 0) {
                zeroCount++;
            }
        }
        while (zeroCount < N) {
            for (int i = 0; i < N; i++) {
                if (a[i] > 0) {
                    if (a[i] % 2 == 1) {
                        muls[i] = muls[i] * tmp % MOD;
                    }
                    a[i] >>= 1;
                    if (a[i] == 0) {
                        zeroCount++;
                    }
                }
            }
            tmp = (tmp * tmp) % MOD;
        }

        long ans = 0;
        for (int i = 0; i < N; i++) {
            ans += muls[i];
        }

        System.out.println(ans % MOD);
    }

}
0