結果

問題 No.16 累乗の加算
ユーザー DialBirdDialBird
提出日時 2016-11-18 20:00:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 473 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 51,488 KB
実行使用メモリ 7,352 KB
最終ジャッジ日時 2023-09-08 12:03:41
合計ジャッジ時間 1,245 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
7,276 KB
testcase_01 AC 10 ms
7,352 KB
testcase_02 AC 10 ms
7,232 KB
testcase_03 AC 10 ms
7,352 KB
testcase_04 AC 10 ms
7,284 KB
testcase_05 AC 9 ms
7,232 KB
testcase_06 AC 9 ms
7,228 KB
testcase_07 AC 9 ms
7,212 KB
testcase_08 AC 10 ms
7,220 KB
testcase_09 AC 9 ms
7,308 KB
testcase_10 AC 10 ms
7,216 KB
testcase_11 AC 10 ms
7,212 KB
testcase_12 AC 9 ms
7,344 KB
testcase_13 AC 10 ms
7,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;

#define REP(i,f,l) for(int i=f;i<l;i++)

const int devider = 1000003;
int x, n;
int table[devider];

int main(){
  cin >> x >> n;
  x %= devider;
  table[0] = 1;

  REP(i,1,devider) {
    table[i] = (table[i-1]*x) % devider;
  }

  int sum = 0;
  int val;
  REP(i,0,n){
    cin >> val;
    //1000003は素数なのでフェルマーの小定理を利用する
    sum += table[val%(devider-1)];
  }

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