結果

問題 No.16 累乗の加算
ユーザー DialBirdDialBird
提出日時 2016-11-19 06:53:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 571 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 51,656 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 12:03:46
合計ジャッジ時間 1,183 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>

using namespace std;

#define REP(i,fast,last) for(int i=fast;i<last;i++)

const int devider = 1000003;
int x, n;

int pow(int x, long long a){
  long long  res = 1;
  long long l = 1;
  if (a > 0) {
    res = pow(l*x*x % devider, a/2);
    if (a%2 == 1) res = res*x % devider;
  }
  return res % devider;
}

int main(){
  cin >> x >> n;
  x %= devider;

  long long sum = 0;
  int val;
  REP(i,0,n){
    cin >> val;
    //1000003は素数なのでフェルマーの小定理を利用する
    sum += pow(x, val);
  }

  cout<<sum % devider<<endl;
}
0