結果

問題 No.16 累乗の加算
ユーザー DialBird
提出日時 2016-11-18 20:00:22
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 473 bytes
コンパイル時間 409 ms
コンパイル使用メモリ 54,496 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-06-26 05:18:25
合計ジャッジ時間 1,134 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

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