結果

問題 No.16 累乗の加算
ユーザー togari_takamototogari_takamoto
提出日時 2016-02-25 18:38:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 794 bytes
コンパイル時間 1,067 ms
コンパイル使用メモリ 144,480 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 11:54:59
合計ジャッジ時間 1,772 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi  = vector<int>; using vb  = vector<bool>; using vd  = vector<double>; using vl  = vector<ll>;
using vvi = vector<vi>;  using vvb = vector<vb>;   using vvd = vector<vd>;     using vvl = vector<vl>;

#define REP(i,n) for(ll i=0; i<(n); ++i)
#define TEN(x) ((ll)1e##x)
#define MOD (TEN(6) + 3)

template<ll mod> struct GF{
	ll v;
	GF(ll v = 0) : v((v % mod + mod) % mod){}
	GF operator+(GF x){return v + x.v;}

	GF pow(ll n) {
		ll x = v, r = 1;
		for (; n > 0; n >>= 1) {
			if (n & 1) (r *= x) %= mod;
			(x *= x) %= mod;
		}
		return r;
	}
};


int main() {
	ll _x, n;
	cin >> _x >> n;

	GF<MOD> x(_x);
	GF<MOD> sum = 0;
	REP(i, n) {
		ll a; cin >> a;
		sum = sum + x.pow(a);
	}

	cout << sum.v << endl;

	return 0;
}
0