結果

問題 No.16 累乗の加算
ユーザー btk
提出日時 2015-05-05 00:47:45
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 429 bytes
コンパイル時間 639 ms
コンパイル使用メモリ 58,704 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 04:53:00
合計ジャッジ時間 1,186 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>


#include<functional>
using namespace std;
#define LL long long
#define mod 1000003
inline LL powmod(LL x, int a){
	LL res = 1;
	for (int i = 0; i < 31; i++){
		if (a&(1 << i))res = (res*x) % mod;
		x = (x*x) % mod;
	}
	return res;

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