結果
| 問題 | 
                            No.16 累乗の加算
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kyo1
                         | 
                    
| 提出日時 | 2020-06-10 15:36:59 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 4 ms / 5,000 ms | 
| コード長 | 1,099 bytes | 
| コンパイル時間 | 2,519 ms | 
| コンパイル使用メモリ | 191,312 KB | 
| 最終ジャッジ日時 | 2025-01-11 00:47:46 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 14 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::enable_if_t<std::is_same<T, int>::value, T> pow(T x, U n, T mod) {
  T res = 1;
  while (n > 0) {
    if (n & 1)
      res = static_cast<T>(static_cast<int64_t>(res) * static_cast<int64_t>(x) %
                           mod);
    x = static_cast<T>(static_cast<int64_t>(x) * static_cast<int64_t>(x) % mod);
    n >>= 1;
  }
  return res;
}
template <typename T, typename U>
std::enable_if_t<std::is_same<T, int64_t>::value, T> pow(T x, U n, T mod) {
  T res = 1;
  while (n > 0) {
    if (n & 1)
      res = static_cast<T>(static_cast<__int128>(res) *
                           static_cast<__int128>(x) % mod);
    x = static_cast<T>(static_cast<__int128>(x) * static_cast<__int128>(x) %
                       mod);
    n >>= 1;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, N;
  cin >> x >> N;
  int res = 0, mod = 1000003;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    res += pow(x, a, mod);
    res %= mod;
  }
  cout << res << '\n';
  return 0;
}
            
            
            
        
            
kyo1