結果

問題 No.16 累乗の加算
ユーザー SSRS
提出日時 2020-08-31 07:40:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 480 bytes
コンパイル時間 769 ms
コンパイル使用メモリ 71,812 KB
最終ジャッジ日時 2025-01-14 02:17:54
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1000003;
long long modpow(long long a, long long b){
	long long ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}
int main(){
	int x, N;
	cin >> x >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++){
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 0; i < N; i++){
		ans += modpow(x, a[i]);
	}
	ans %= MOD;
	cout << ans << endl;
}
0