結果

問題 No.16 累乗の加算
ユーザー atkrymatkrym
提出日時 2016-11-07 16:23:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 5,000 ms
コード長 1,429 bytes
コンパイル時間 2,030 ms
コンパイル使用メモリ 74,248 KB
実行使用メモリ 55,916 KB
最終ジャッジ日時 2023-09-08 12:03:00
合計ジャッジ時間 4,772 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,548 KB
testcase_01 AC 129 ms
55,520 KB
testcase_02 AC 137 ms
55,568 KB
testcase_03 AC 133 ms
55,324 KB
testcase_04 AC 133 ms
55,440 KB
testcase_05 AC 136 ms
55,876 KB
testcase_06 AC 140 ms
55,544 KB
testcase_07 AC 135 ms
55,692 KB
testcase_08 AC 138 ms
55,672 KB
testcase_09 AC 137 ms
55,916 KB
testcase_10 AC 136 ms
55,528 KB
testcase_11 AC 127 ms
55,300 KB
testcase_12 AC 139 ms
55,548 KB
testcase_13 AC 140 ms
55,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    private static long[] ary;
    private static final long MOD = 1000003;
    public static void main(String[] args) throws Exception {
        long x = nextLong();
        int n = nextInt();
        ary = nextLong(n);
        long ans = 0;
        for (int i = 0;i < n;i++) {
            ans = (ans+pow(x, ary[i]))%MOD;
        }
        System.out.println(ans);
    }
    
    private static long pow(long n, long p) {
        long ret = 1;
        while (p > 0) {
            if ((p&1)==1) ret = ret*n%MOD;
            n = n*n%MOD;
            p >>= 1;
        }
        return ret;
    }

    private static int nextInt() { return sc.nextInt(); }
    private static long nextLong() { return sc.nextLong(); }
    private static float nextFloat() { return sc.nextFloat(); }

    private static int[] nextInt(int n) {
        int[] ret = new int[n];
        for (int i = 0;i < n;i++) {
            ret[i] = nextInt();
        }
        return ret;
    }

    private static long[] nextLong(int n) {
        long[] ret = new long[n];
        for (int i = 0;i < n;i++) {
            ret[i] = nextLong();
        }
        return ret;
    }

    private static float[] nextFloat(int n) {
        float[] ret = new float[n];
        for (int i = 0;i < n;i++) {
            ret[i] = nextFloat();
        }
        return ret;
    }
}
0