結果

問題 No.16 累乗の加算
ユーザー 👑 obakyan
提出日時 2019-04-20 13:37:20
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 635 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 71,968 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-01 06:48:52
合計ジャッジ時間 1,018 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <iostream>
#include <iomanip>
#define L64 long long
#define MOD (1000003LL)

L64 modpow(L64 src, L64 pow)
{
  L64 res = 1;
  while (0 < pow) {
    if (pow % 2 == 1) {
      res = (res * src) % MOD;
      pow--;
    }
    src = (src * src) % MOD;
    pow /= 2;
  }
  return res;
}

int main(void)
{
  L64 x, n;
  std::cin >> x >> n;
  L64 sum = 0;
  for(L64 i = 0; i < n; i++){
    L64 a;
    std::cin >> a;
    sum = (sum + modpow(x, a)) % MOD;
  }
  std::cout << sum << std::endl;
  return 0;
}
0