結果
| 問題 | 
                            No.16 累乗の加算
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-01-06 16:22:07 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 422 bytes | 
| コンパイル時間 | 524 ms | 
| コンパイル使用メモリ | 64,896 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-23 23:52:22 | 
| 合計ジャッジ時間 | 1,093 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 14 | 
ソースコード
#include <iostream>
using namespace std;
#define N 100000000
#define Q 1000003
typedef long long LLI;
LLI pow(LLI x, int n){
  LLI ans;
  if (n==0) return 1;
  ans = pow(x*x%Q, n/2);
  if (n%2) ans *= x;
  return ans%Q;
}
int main(void){
  int x,n;
  LLI ans;
  
  cin >> x >> n;
  ans = 0;
  for (int i=0; i<n; i++){
    int a;
    cin >> a;
    ans += pow(x,a);
    ans %= Q;
  }
  cout << ans << endl;
  return 0;
}