結果

問題 No.16 累乗の加算
コンテスト
ユーザー wild
提出日時 2017-03-11 02:20:16
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 455 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 543 ms
コンパイル使用メモリ 82,300 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2026-03-12 19:50:32
合計ジャッジ時間 1,025 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
using namespace std;

const int BIG = 1000003;
long pow(long n, int r){
	if(r==0) return  1;
	if(r%2 == 0) return pow((n*n)%BIG, r/2);
	else return (n*pow(n, r-1))%BIG;
}
	

int main(){
	int x, n;
	cin >> x >> n;
	vector<int> v(n);
	for(int i=0; i<n; i++)cin >> v[i];

	long sum =0;
	for(int i=0; i<n; i++){
		sum += pow(x, v[i]);
		sum = sum % BIG;
		//cout << pow(x, v[i]) << endl;
	}
	
	cout << sum << endl;
}
		
	

0