結果

問題 No.16 累乗の加算
ユーザー trineutron
提出日時 2019-07-23 21:30:23
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 457 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 166,592 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-26 09:18:28
合計ジャッジ時間 2,464 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:23:17: warning: 's' may be used uninitialized [-Wmaybe-uninitialized]
   23 |     cout << s % 1000003 << endl;
      |                 ^~~~~~~
main.cpp:16:15: note: 's' was declared here
   16 |     int x, n, s;
      |               ^

ソースコード

diff #

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

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

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