結果

問題 No.16 累乗の加算
ユーザー hanorverhanorver
提出日時 2016-05-03 16:19:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 469 bytes
コンパイル時間 1,192 ms
コンパイル使用メモリ 64,144 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 11:58:50
合計ジャッジ時間 1,496 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>

#define W 1000003

long long pow(long long x, int num) {
	if (num == 0) return 1;
	if (num == 1) return x;
	if (num % 2 == 0) {
		long long n = pow(x, num / 2);
		return (n * n) % W;
	} else {
		return pow(x, num - 1) * x % W;
	}
}

int main() {
	long long x, n;
	std::cin >> x >> n;

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		int num;
		std::cin >> num;

		ans += pow(x, num);
		ans %= W;
	}

	std::cout << ans << std::endl;
	return 0;
}
0