結果
| 問題 | 
                            No.16 累乗の加算
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2017-02-07 10:10:10 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 4 ms / 5,000 ms | 
| コード長 | 691 bytes | 
| コンパイル時間 | 597 ms | 
| コンパイル使用メモリ | 60,956 KB | 
| 実行使用メモリ | 7,276 KB | 
| 最終ジャッジ日時 | 2024-06-26 05:19:41 | 
| 合計ジャッジ時間 | 1,205 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 14 | 
ソースコード
#include <iostream>
#include <vector>
using namespace std;
#define REP(i,first,last) for (int i=first;i<last;i++)
const int devider = 1000003;
int x, N;
vector<int> dp(devider-1, -1);
int my_pow(long long x, int idx){
  int res = 1; 
  if (idx > 0) {
    res = my_pow(x*x % devider, idx/2);
    if (idx & 1) res = res * x % devider;
  }
  return res % devider;
}
int main(){
  cin >> x;
  cin >> N;
  x %= devider;
  int val;
  int amari;
  long long total = 0;
  REP(i,0,N) {
    cin >> val;
    amari = val % (devider - 1);
    if (dp[amari] == -1) {
      dp[amari] = my_pow(x, amari);
    }
    total += dp[amari];
    total %= devider;
  }
  cout << (total % devider) << endl;
}