結果

問題 No.16 累乗の加算
ユーザー daleksprinterdaleksprinter
提出日時 2018-09-02 11:03:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 946 bytes
コンパイル時間 677 ms
コンパイル使用メモリ 76,968 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 22:17:24
合計ジャッジ時間 1,245 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
int mod = (int)(1e6 + 3);

int ceil(int a, int b){
    if (a % b){
        return a/b + 1;
    }else
        return a/b;
}

typedef unsigned long long ull;

ull pow(ull p, ull n) {
  ull w = 1;
  for (ull i = 1ULL << (sizeof(ull)*8-1); i != 0; i >>= 1) {
    if ((n & i) == 0) {
      w *= w;
    } else {
      w *= w * p;
    }
  }
  return w;
}

ull modpow(ull p, ull n, ull m) {
  ull w = 1;
  for (ull i = 1ULL << (sizeof(ull)*8-1); i != 0; i >>= 1) {
    if ((n & i) == 0) {
      w *= w;
    } else {
      w *= w * p;
    }
    w %= m;
  }
  return w;
}
int main(){
    int x,n;
    cin >> x >> n;
    vector<int> arr;
    while (n--){
        int t;
        cin >> t;
        arr.push_back(t);
    }
    int ans = 0;
    for(auto e:arr){
        ans += modpow(x,e,mod);
    }
    cout << ans << endl;
}
0