結果

問題 No.1396 Giri
ユーザー mine691mine691
提出日時 2021-02-14 21:53:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 1,747 bytes
コンパイル時間 2,184 ms
コンパイル使用メモリ 210,664 KB
実行使用メモリ 10,828 KB
最終ジャッジ日時 2023-09-29 15:14:35
合計ジャッジ時間 5,414 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 269 ms
10,736 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 266 ms
10,784 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 20 ms
4,380 KB
testcase_19 AC 137 ms
7,172 KB
testcase_20 AC 189 ms
8,756 KB
testcase_21 AC 239 ms
10,100 KB
testcase_22 AC 260 ms
10,828 KB
testcase_23 AC 267 ms
10,740 KB
testcase_24 AC 270 ms
10,808 KB
testcase_25 AC 271 ms
10,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr static int mod = 1e9 + 7;
constexpr static int inf = (1 << 30) - 1;
constexpr static Int infll = (1LL << 61) - 1;
int Competitive_Programming = (ios_base::sync_with_stdio(false), cin.tie(nullptr), cout << fixed << setprecision(15), 0);
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

// for query using osa_k way

// init table
vector<int> sieve(int N)
{
	vector<int> res(N + 1);

	for (int i = 2; i <= N; i++)
	{
		if (res[i] == 0)
		{
			for (int j = i; j <= N; j += i)
			{
				if (res[j] == 0)
					res[j] = i;
			}
		}
	}
	return res;
}

// prime factorization O(log N)
vector<int> prime_factor(int N, const vector<int> &min_factor)
{
	// min_factor is vector which got by sieve()
	vector<int> res;
	while (N > 1)
	{
		res.push_back(min_factor[N]);
		N /= min_factor[N];
	}
	return res;
}

bool is_prime(int N, const vector<int> &min_factor)
{
	return min_factor[N] == N;
}

using ll = long long;

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

int main()
{
	int N;
	cin >> N;
	auto mi = sieve(N + 1);
	int ex = 0;
	for (int i = N; i > 1; i--)
	{
		if (is_prime(i, mi))
		{
			ex = i;
			break;
		}
	}

	vector<int> mp(N + 1, 0);
	mp[1]++;

	for (int i = 2; i <= N; i++)
	{
		if (i == ex)
			continue;
		auto p = prime_factor(i, mi);
		map<int, int> q;
		for (int j = 0; j < p.size(); j++)
			q[p[j]]++;

		for (auto &&e : q)
			mp[e.first] = max(mp[e.first], e.second);
	}

	Int ans = 1;

	int m = 998244353;
	for (int i = 2; i <= N; i++)
	{
		ans *= mod_pow((Int)i, mp[i], m);
		ans %= m;
	}

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