結果

問題 No.16 累乗の加算
ユーザー kpinkcat
提出日時 2023-10-09 02:03:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 656 bytes
コンパイル時間 776 ms
コンパイル使用メモリ 102,684 KB
最終ジャッジ日時 2025-02-17 06:22:00
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<math.h>
#include<bitset>
using ll = long long;
using namespace std;

int main(){
    ll x, n, ans = 0, mod = 1000003;
    cin >> x >> n;
    for (int i = 0; i < n; i++){
        ll a, x1, tmp= 1;
        cin >> a;
        x1 = 1;
        tmp = x;
        while (a){ 
            if (a & 1) {
                x1 *= tmp;
                x1 %= mod;
            }
            tmp *= tmp;
            tmp %= mod;
            a >>= 1;
        }
        ans += x1;
        ans %= mod;
    }
    cout << ans << endl;
}
0