結果

問題 No.16 累乗の加算
ユーザー kano_townkano_town
提出日時 2014-11-19 17:47:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 530 bytes
コンパイル時間 3,461 ms
コンパイル使用メモリ 71,948 KB
実行使用メモリ 58,056 KB
最終ジャッジ日時 2023-09-08 11:30:45
合計ジャッジ時間 5,917 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,448 KB
testcase_01 AC 123 ms
55,952 KB
testcase_02 AC 135 ms
55,856 KB
testcase_03 AC 128 ms
55,796 KB
testcase_04 AC 128 ms
56,416 KB
testcase_05 AC 130 ms
58,056 KB
testcase_06 AC 134 ms
55,728 KB
testcase_07 AC 131 ms
55,780 KB
testcase_08 AC 133 ms
55,712 KB
testcase_09 AC 133 ms
55,648 KB
testcase_10 AC 133 ms
56,156 KB
testcase_11 AC 122 ms
55,920 KB
testcase_12 AC 135 ms
56,072 KB
testcase_13 AC 133 ms
55,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Yukicoder16 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int N = sc.nextInt();
		long res = 0;
		for (int i = 0; i < N; i++) {
			res += powMod(x, sc.nextInt()) % 1000003;
		}
		System.out.println(res % 1000003);
	}

	private static long powMod(long a, int n) {
		long res = 1;
		for (; n > 0; n>>=1) {
			res = (n & 1) == 1 ? (a * res) % 1000003 : res;
			a = (a * a) % 1000003;
		}
		return res;
	}
}
0