結果

問題 No.16 累乗の加算
ユーザー YamaKasaYamaKasa
提出日時 2018-06-13 00:52:25
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 622 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 71,332 KB
実行使用メモリ 61,440 KB
最終ジャッジ日時 2023-09-13 03:44:40
合計ジャッジ時間 9,171 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,108 KB
testcase_01 AC 119 ms
56,280 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int N = scan.nextInt();
		long []a = new long[N];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		}
		scan.close();
		int k = 1000003;
		long ans = 0;
		for(int i = 0; i < N; i++) {
			long t = x % k;
			if(a[i] == 0) {
				ans ++;
				ans = ans % k;
			}else if(a[i] == 1) {
				ans += x % k;
			}else {
				for(int j = 2; j <= a[i]; j++) {
					t = (t * x) % k;
				}
				ans = ans + t % k;
				ans = ans % k;
			}

		}
		System.out.println(ans);
	}
}
0