結果

問題 No.16 累乗の加算
ユーザー Irmystp
提出日時 2014-12-03 12:55:18
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 499 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 23,168 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 04:47:52
合計ジャッジ時間 757 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |     scanf("%lld %d", &x, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:21:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |         scanf("%d", &a);
      |         ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <cstdio>
using namespace std;

const int MOD = 1000003;

typedef long long LL;

LL pow(LL x, int a){
    if(a == 0) return 1;
    if(a % 2) return (x * pow(x, a-1)) % MOD;
    LL ret = pow(x, a/2) % MOD;
    return (ret * ret) % MOD;
}

int main(){
    LL x, r;
    int n, a;
    scanf("%lld %d", &x, &n);
    r = 0;
    for(int i = 0; i < n; i++){
        scanf("%d", &a);
        r += pow(x, a);
        r %= MOD;
    }
    printf("%lld\n", r);
    return 0;
}
0