結果

問題 No.16 累乗の加算
コンテスト
ユーザー vrjfsyi
提出日時 2018-03-25 10:35:37
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 824 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 616 ms
コンパイル使用メモリ 97,464 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-12 20:04:00
合計ジャッジ時間 1,207 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <array>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;

long pow(long x, long n, long m) {
    long ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = (ans * x) % m;
        }
        x = x * x % m;
        n = n >> 1;
    }
    return ans % m;
}

int main() {

    int x, N;
    cin >> x >> N;

    map<long, long> m;
    long modulo = 1000003;
    long a;
    long result = 0;
    for (int j = 0; j < N; ++j) {
        cin >> a;
        if (m.find(a) != m.end()) {
            result += m[a];
        } else {
            long b = pow(x, a, modulo);
            result += b;
            m[a] = b;
        }
    }

    cout << (result % modulo) << "\n";

    return 0;
}

0