結果
| 問題 |
No.1396 Giri
|
| コンテスト | |
| ユーザー |
mine691
|
| 提出日時 | 2021-02-14 21:53:36 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 271 ms / 2,000 ms |
| コード長 | 1,747 bytes |
| コンパイル時間 | 1,941 ms |
| コンパイル使用メモリ | 207,956 KB |
| 最終ジャッジ日時 | 2025-01-18 20:55:55 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#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';
}
mine691