結果

問題 No.16 累乗の加算
ユーザー Nagisa
提出日時 2016-02-16 01:39:20
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 546 bytes
コンパイル時間 1,753 ms
コンパイル使用メモリ 54,612 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-27 04:45:13
合計ジャッジ時間 2,456 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:13: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |     cout << ans << endl;
      |             ^~~

ソースコード

diff #

#include <iostream>
using namespace std;
typedef long long ll;
const ll mod = 1000003;

// from the Arihon
ll mod_pow(ll x, ll n, ll m){
	ll res = 1;
	while (n > 0){
	if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

int main()
{   int x, N, ans;
	cin >> x >> N;
	long long a[N];
	for (int i = 0; i < N; i++) {
		a[i] = 0;
	}
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		long long p = mod_pow(x,a[i],mod);
		ans += p;
		ans = ans%mod;
	}
    cout << ans << endl;
    return 0;
}
0