結果

問題 No.16 累乗の加算
ユーザー otsnsk
提出日時 2015-01-19 19:59:15
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 957 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 60,376 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 04:48:24
合計ジャッジ時間 1,224 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

#define FORR(i,b,e) for(int i=(b);i<(int)(e);++i)
#define FOR(i,e) FORR(i,0,e)
#define dump(var) cerr << #var ": " << var << "\n"
#define dumpc(con) for(auto& e: con) cerr << e << " "; cerr<<"\n"

typedef long long ll;
typedef unsigned long long ull;

const ll MODD = 1000003;

using namespace std;

ll x, N;
vector<ll> pp;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> x >> N;

    pp.reserve(100);
    pp.push_back(x);
    ll v = x*x;
    int ex = 1; 
    pp.push_back(v);
    while (ex < 100000000) {
        v = (v * v) % MODD;
        ex *= 2;
        pp.push_back(v);
    }
    
    ll ans = 0;
    FOR(i, N) {
        int a;
        cin >> a;
        ll v = 1;
        auto p = pp.begin();
        while (a) {
            if (a&1) v = (v * (*p)) % MODD;
            a >>= 1;
            p++;
        }
        ans = (ans + v) % MODD;
    }
    cout << ans << endl;

    return 0;
}
0