結果

問題 No.16 累乗の加算
ユーザー kibou1136kibou1136
提出日時 2021-12-15 10:21:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 511 bytes
コンパイル時間 1,407 ms
コンパイル使用メモリ 165,104 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-10-01 02:27:17
合計ジャッジ時間 2,333 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000003;

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

int main(){
    long long n, a; cin >> a >> n;
    long long x[n + 1] = {0};
    x[0] = 1;
    long long res = 0;
    for (int i = 1;i <= n; ++i){
        cin >> x[i];
        res = (res + pow(a, x[i]))%mod;
    }

    cout << res << endl;
   



}
0