結果

問題 No.16 累乗の加算
ユーザー bal4ubal4u
提出日時 2019-04-07 22:22:36
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 502 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 28,688 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 08:52:57
合計ジャッジ時間 970 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yukicoder: No.16 累乗の加算
// 2019.4.7 bal4u
// 累乗の高速計算

#include <stdio.h>

#define MOD 1000003 
int x, N;

int myPow(int x, int n)  // x^n
{
	long long ans = 1;
	long long xx = x;

	while (n > 0) {
		if (n & 1) ans = (ans * xx) % MOD, n--;
		else xx = (xx * xx) % MOD, n >>= 1;
	}
	return (int)ans;
}

int main()
{
	int i, a, ans;

	scanf("%d%d", &x, &N);
	ans = 0;
	for (i = 0; i < N; i++) {
		scanf("%d", &a);
		ans += myPow(x, a);
	}
	printf("%d\n", ans % MOD);
	return 0;
}
0