結果

問題 No.16 累乗の加算
ユーザー trineutrontrineutron
提出日時 2019-07-23 21:33:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 475 bytes
コンパイル時間 1,425 ms
コンパイル使用メモリ 164,328 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-08 16:31:26
合計ジャッジ時間 2,122 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int power(int x, int a) {
    if (a == 0) return 1;
    if (x == 0) return 0;
    if (a % 2 == 0) {
        return power((long) x * x % 1000003, a / 2);
    } else {
        return power((long) x * x % 1000003, a / 2) * x % 1000003;
    }
}

int main()
{
    int x, n, s = 0;
    cin >> x >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        s += power(x, a);
    }
    cout << s % 1000003 << endl;
}
0