結果

問題 No.16 累乗の加算
ユーザー DialBirdDialBird
提出日時 2016-12-17 13:24:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 850 bytes
コンパイル時間 588 ms
コンパイル使用メモリ 62,496 KB
実行使用メモリ 7,280 KB
最終ジャッジ日時 2024-05-08 04:05:30
合計ジャッジ時間 1,117 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,188 KB
testcase_01 AC 4 ms
7,040 KB
testcase_02 AC 4 ms
7,168 KB
testcase_03 AC 3 ms
7,128 KB
testcase_04 AC 4 ms
7,040 KB
testcase_05 AC 4 ms
7,280 KB
testcase_06 AC 4 ms
7,168 KB
testcase_07 AC 4 ms
7,168 KB
testcase_08 AC 3 ms
7,168 KB
testcase_09 AC 4 ms
7,104 KB
testcase_10 AC 5 ms
7,168 KB
testcase_11 AC 4 ms
7,124 KB
testcase_12 AC 4 ms
7,072 KB
testcase_13 AC 4 ms
7,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

#define REP(i,first,last) for (int i=first;i<last;i++)
#define FOR(it,con) for (auto it=con.begin();it!=con.end();it++)

const int devider = 1000002;
int x,N;
vector<int> amari_list(devider, -1);

int pow(long long x, long long a){
  int res = 1;
  if (a > 0) {
    res = pow(x*x % (devider+1), a/2);
    if (a%2 == 1) res = res*x % (devider+1);
  }
  return res % (devider+1);
}

int main(){
  cin >> x;
  cin >> N;
  x %= (devider+1);
  int val;
  long long result = 0;
  REP(i,0,N) {
    cin >> val;
    int target = val % devider;

    if (amari_list[target] == -1) {
      int amari = pow(x, target);
      amari_list[target] = amari;
    }
    result += amari_list[target];
    result %= (devider+1);
  }

  cout<<result % (devider + 1)<<endl;
}
0