結果

問題 No.16 累乗の加算
ユーザー rn4rurn4ru
提出日時 2016-04-13 03:06:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 642 bytes
コンパイル時間 2,357 ms
コンパイル使用メモリ 71,408 KB
実行使用メモリ 56,044 KB
最終ジャッジ日時 2023-09-08 11:57:38
合計ジャッジ時間 4,890 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,668 KB
testcase_01 AC 125 ms
55,716 KB
testcase_02 AC 135 ms
55,760 KB
testcase_03 AC 128 ms
55,612 KB
testcase_04 AC 128 ms
56,004 KB
testcase_05 AC 131 ms
56,044 KB
testcase_06 AC 134 ms
55,780 KB
testcase_07 AC 132 ms
55,620 KB
testcase_08 AC 132 ms
55,696 KB
testcase_09 AC 135 ms
55,592 KB
testcase_10 AC 133 ms
55,860 KB
testcase_11 AC 121 ms
55,696 KB
testcase_12 AC 133 ms
55,924 KB
testcase_13 AC 133 ms
55,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	final static int mod = 1000003;

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt();
		int N = scanner.nextInt();

		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = scanner.nextInt();
		}

		int sum = 0;
		for (int i = 0; i < N; i++) {
			sum += myPow(x, a[i]);
		}
		System.out.println(sum % mod);
	}

	private static long myPow(int x, int i) {
		if (i == 0) {
			return 1;
		}

		if (i % 2 == 1) {
			return (x * myPow(x, i - 1)) % mod;
		} else {
			long s = myPow(x, i / 2);
			return (s * s) % mod;
		}
	}

}
0