結果

問題 No.16 累乗の加算
ユーザー yuimyoyuimyo
提出日時 2022-02-17 22:00:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 847 bytes
コンパイル時間 1,441 ms
コンパイル使用メモリ 165,452 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 17:53:49
合計ジャッジ時間 2,831 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vt vector
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
ll MOD = 1000003;
ll M = 32;
ll dob(ll x, ll a) {
    vt<ll> d(M);
    d[0] = 1;
    d[1] = x;
    for (ll i = 1; i < M - 1; i++) {
        d[i + 1] = (d[i] * d[i]) % MOD;
    }
    ll ans = 1;
    for (ll i = M - 1; i >= 1; i--) {
        if (a & (1 << (i - 1))) {
            ans = (ans * d[i]) % MOD;
        }
    }
    return ans;
}

int main() {
    ll x, N;
    cin >> x >> N;
    ll ans = 0;
    rep(i, N) {
        ll a;
        cin >> a;
        ans = (ans + dob(x, a)) % MOD;
    }
    cout << ans << endl;
}
0