結果

問題 No.16 累乗の加算
ユーザー elphe
提出日時 2024-08-19 12:42:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 708 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 76,132 KB
最終ジャッジ日時 2025-02-23 23:10:35
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC   target("sse4,avx,tune=native")
#pragma GCC   optimize("O3")
#pragma GCC   optimize("unroll-loops")

#include <iostream>
#include <cstdint>

#define MOD  1'000'003

using namespace std;

constexpr unsigned int pow_mod(const unsigned long long a, const unsigned long long b, const unsigned int mod)
{
	return (b == 0 ? (mod == 1 ? 0 : 1) : (b & 1 ? a % mod : 1) * pow_mod((a % mod) * (a % mod) % mod, b >> 1, mod) % mod);
}

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	uint16_t x, N, i;
	uint32_t a[100], ans = 0;
	cin >> x >> N;
	for (i = 0; i != N; ++i) cin >> a[i];

	for (i = 0; i != N; ++i)
		ans = (ans + pow_mod(x, a[i], MOD)) % MOD;

	cout << ans << '\n';
	return 0;
}
0