結果

問題 No.16 累乗の加算
ユーザー 古寺いろは
提出日時 2015-04-15 23:16:39
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 439 bytes
コンパイル時間 1,221 ms
コンパイル使用メモリ 158,712 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-26 04:52:04
合計ジャッジ時間 1,861 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

long long mod = 1000003;

long long powmod(long long a, int p){
	if (p == 0) return 1;
	if (p % 2 == 1){
		return a * powmod(a, p - 1) % mod;
	}
	long long c = powmod(a, p / 2);
	return c * c % mod;
}

int main() {
	long long x;
	int N;
	cin >> x >> N;
	long long ans = 0;
	for (int i = 0; i < N; i++)
	{
		int a;
		cin >> a;
		ans += powmod(x, a);
	}
	ans %= mod;
	cout << ans << endl;
}



0