結果

問題 No.16 累乗の加算
ユーザー  nemunemu nemunemu
提出日時 2023-05-01 10:00:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 589 bytes
コンパイル時間 572 ms
コンパイル使用メモリ 70,748 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-30 14:31:17
合計ジャッジ時間 1,233 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 1000003;

int powermod(ll a, ll b, ll MOD) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
        b = b >> 1;
    }
    return (int)res;
}

int main() {
    int x, N;
    cin >> x >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    int res = 0;
    for (int i = 0; i < N; ++i) {
        res += powermod(x, a[i], MOD);
        res %= MOD;
    }
    cout << res << endl;
}
0