結果

問題 No.16 累乗の加算
ユーザー ty70ty70
提出日時 2015-06-13 10:27:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,685 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 87,380 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 11:40:26
合計ジャッジ時間 1,400 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

/*
	No.16 累乗の加算

	累乗の計算

ループ版
ll mod_pow (ll x, ll n, ll mod )
{
	ll res = 1LL;
	while (n > 0 ){
		if (n & 1 ) res = res*x % mod;
		x = x*x % mod;
		n >>=1;
	} // end while
		
	return res;
}

再帰版
ll mod_pow (ll x, ll n, ll mod )
{
	if (n == 0 ) return 1LL;
	ll res = mod_pow (x*x % mod, n / 2, mod );
	if (n & 1 ) res = res * x % mod;
		
	return res;
}

*/

using namespace std;

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

const ll MOD = (ll)1e6 + 3LL; 

ll mod_pow (ll x, ll n, ll mod )
{
	if (n == 0LL ) return 1LL;
	ll res = mod_pow (x*x % mod, n / 2LL, mod );
	if (n & 1LL ) res = (res * x ) % mod;
		
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	ll x, N; cin >> x >> N;
	vector<ll> a(N, 0LL );
	rep (i, N ) cin >> a[i];

	ll res = 0LL;
	rep (i, N ){
		res = (res + mod_pow(x, a[i], MOD ) ) % MOD;
	} // end rep

	cout << (int)res << endl;

	return 0;
}
0