結果

問題 No.16 累乗の加算
ユーザー Naoyk1212Naoyk1212
提出日時 2016-10-14 22:03:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 479 bytes
コンパイル時間 1,274 ms
コンパイル使用メモリ 144,200 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 12:02:14
合計ジャッジ時間 2,067 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

long long pow_mod(long long n, long long p, long long m){
	if (p == 0){
		return 1;
	}else if(p % 2 == 1){
		return pow_mod(n, p - 1, m) * n % m;
	}else{
		long long t = pow_mod(n, p / 2, m);
		return t * t % m;
	}
}

int main(){
  int x, n;
  cin >> x >> n;
  long long ans = 0;
  long long mod = 1e6 + 3;
  int a;
  for(int i = 0; i < n; i++){
    cin >> a;
    ans += pow_mod(x, a, mod);
  }
  ans %= mod;
  cout << ans << endl;
}
0