結果

問題 No.16 累乗の加算
ユーザー hotpepsihotpepsi
提出日時 2015-03-03 01:25:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 686 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 67,772 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 11:34:32
合計ジャッジ時間 1,488 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <set>
#include <vector>

using namespace std;
const int MOD = 1000003;

int main(int argc, char *argv[]) {
	string s;
	getline(cin, s);
	int x, N;
	{
		stringstream ss(s);
		ss >> x >> N;
	}
	vector<long long> a(N), b(N, 1);
	getline(cin, s);
	{
		stringstream ss(s);
		for (int i = 0; i < N; ++i) {
			ss >> a[i];
		}
	}
	long long p = 1, q = x;
	for (int i = 1; i <= 30; ++i) {
		for (int j = 0; j < N; ++j) {
			if (a[j] & p) {
				b[j] = (b[j] * q) % MOD;
			}
		}
		p *= 2;
		q = (q * q) % MOD;
	}
	long long ans = accumulate(b.begin(), b.end(), 0LL) % MOD;
	cout << ans << endl;
	return 0;
}
0