結果

問題 No.16 累乗の加算
ユーザー たこしたこし
提出日時 2014-11-13 22:17:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,128 bytes
コンパイル時間 620 ms
コンパイル使用メモリ 85,776 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 11:29:46
合計ジャッジ時間 1,326 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define INF 1000000000
#define EPS 1e-9
#define PI acos(-1)

typedef long long ll;
typedef pair<int, int> P;

#define MAX_N 100
#define mod 1000003

int x, N;
int a[MAX_N];

ll xx[MAX_N];

void init(){
  xx[1] = x;
  for(int i = 2; i < MAX_N; i++){
    xx[i] = (xx[i-1] * xx[i-1])%mod;
  }
}

ll solve(int n){
  ll ans = 1;
  for(int i = 0; n > 0; i++){
    if(n & 1)
      ans = (ans*xx[i+1])%mod;
    n >>= 1;
  }
  return ans;
}

int main(){

  cin >> x >> N;
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }

  init();
  ll ans = 0;
  for(int i = 0; i < N; i++){
    ans = (ans + solve(a[i]))%mod;
  }

  cout << ans << endl;

  return 0;
  
}
0