結果

問題 No.16 累乗の加算
ユーザー t8m8⛄️t8m8⛄️
提出日時 2015-04-04 00:36:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 137 ms / 5,000 ms
コード長 1,072 bytes
コンパイル時間 3,470 ms
コンパイル使用メモリ 76,972 KB
実行使用メモリ 56,340 KB
最終ジャッジ日時 2023-09-08 11:36:08
合計ジャッジ時間 6,099 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,084 KB
testcase_01 AC 127 ms
55,968 KB
testcase_02 AC 137 ms
55,596 KB
testcase_03 AC 127 ms
55,788 KB
testcase_04 AC 128 ms
56,340 KB
testcase_05 AC 133 ms
55,792 KB
testcase_06 AC 134 ms
56,120 KB
testcase_07 AC 134 ms
55,780 KB
testcase_08 AC 134 ms
56,068 KB
testcase_09 AC 134 ms
55,704 KB
testcase_10 AC 134 ms
55,716 KB
testcase_11 AC 124 ms
56,044 KB
testcase_12 AC 133 ms
55,948 KB
testcase_13 AC 130 ms
56,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//No.16 累乗の加算

import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class No16 {
    
    static final Scanner sc = new Scanner(System.in);
    static final PrintWriter out = new PrintWriter(System.out,false);

    static void solve() {
        int x = sc.nextInt();
        int n = sc.nextInt();
        long ans = 0;
        for (int i=0; i<n; i++) {
            ans = (ans + modPow(x,sc.nextInt(),1000003))%1000003;
        }
        out.println(ans);
    }

    static long modPow(long x, long n, long m) {
        long ret = 1;
        while (n > 0) {
            if ((n&1) == 1) ret = ret*x %m;
            x = x*x %m;
            n >>= 1;
        }
        return  ret;
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        solve();
        out.flush();

        long end = System.currentTimeMillis();
        //trace(end-start + "ms");
        sc.close();
    }

    static void trace(Object... o) { System.out.println(deepToString(o));}
}
0