結果

問題 No.16 累乗の加算
ユーザー mobius_bkstmobius_bkst
提出日時 2015-05-03 13:14:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 1,447 bytes
コンパイル時間 5,551 ms
コンパイル使用メモリ 74,592 KB
実行使用メモリ 50,932 KB
最終ジャッジ日時 2023-09-08 11:37:07
合計ジャッジ時間 4,957 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,508 KB
testcase_01 AC 44 ms
49,528 KB
testcase_02 AC 63 ms
50,748 KB
testcase_03 AC 49 ms
49,908 KB
testcase_04 AC 51 ms
50,056 KB
testcase_05 AC 53 ms
49,960 KB
testcase_06 AC 57 ms
50,340 KB
testcase_07 AC 57 ms
50,088 KB
testcase_08 AC 60 ms
50,892 KB
testcase_09 AC 61 ms
50,928 KB
testcase_10 AC 59 ms
50,932 KB
testcase_11 AC 45 ms
49,172 KB
testcase_12 AC 56 ms
50,100 KB
testcase_13 AC 45 ms
49,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class NO016 {

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    System.in));
            long[] xN = strTointArray(br.readLine());
            BigInteger[] a = strTointArrayBigInt(br.readLine());
            BigInteger x = new BigInteger(Long.toString(xN[0]));
            BigInteger ans = new BigInteger("0");
            BigInteger mod = new BigInteger("1000003");
            for (int i = 0; i < xN[1]; i++) {
                ans = ans.add(x.modPow(a[i], mod));
            }

            System.out.println(ans.mod(mod));
        } catch (Exception e) {
            System.err.println("Error:" + e.getMessage());
        }
    }

    static long[] strTointArray(String S) {
        String[] strArray = S.split(" ");
        long[] longArray = new long[strArray.length];
        for (int i = 0; i < strArray.length; i++) {
            longArray[i] = Long.parseLong(strArray[i]);
        }
        return longArray;
    }

    static BigInteger[] strTointArrayBigInt(String S) {
        String[] strArray = S.split(" ");
        BigInteger[] longArray = new BigInteger[strArray.length];
        for (int i = 0; i < strArray.length; i++) {
            longArray[i] = new BigInteger(strArray[i]);
        }
        return longArray;
    }
}
0