結果
問題 | No.16 累乗の加算 |
ユーザー |
![]() |
提出日時 | 2016-02-25 18:38:16 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 794 bytes |
コンパイル時間 | 1,282 ms |
コンパイル使用メモリ | 158,056 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 05:09:45 |
合計ジャッジ時間 | 1,907 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
ソースコード
#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; }