結果

問題 No.16 累乗の加算
コンテスト
ユーザー Zu_rin
提出日時 2020-04-30 17:09:41
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 691 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 648 ms
コンパイル使用メモリ 88,192 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-26 09:42:58
合計ジャッジ時間 1,248 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:38:21: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
   38 |                 ans += Pow(a, k);
      |                 ~~~~^~~~~~~~~~~~
main.cpp:34:15: note: 'ans' was declared here
   34 |         ll a, ans;
      |               ^~~

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000003
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

ll Pow(ll n, ll k) {
	ll ans = 1, a = n % MOD;
	while (k > 0) {
		if (k & 1) {
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		k >>= 1;
	}
	return ans;
}

int main(void) {
	int num, i, k;
	ll a, ans;
	cin >> a >> num;
	rep(i, num) {
		cin >> k;
		ans += Pow(a, k);
		ans %= MOD;
	}
	cout << ans << "\n";
	return 0;
}
0