結果
| 問題 |
No.1529 Constant Lcm
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-04 20:35:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 5,755 bytes |
| コンパイル時間 | 1,804 ms |
| コンパイル使用メモリ | 199,652 KB |
| 最終ジャッジ日時 | 2025-01-21 22:12:54 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 17 WA * 7 |
ソースコード
#line 1 "/workspaces/compro/lib/math/modint.hpp"
#include <cassert>
#include <cstdint>
#include <iostream>
#include <vector>
#ifndef MOD_INT
#define MOD_INT
template <std::uint_fast64_t MOD> class ModInt {
using u64 = std::uint_fast64_t;
public:
ModInt(const u64 val = 0) { value = val % MOD; }
ModInt operator+(const ModInt rhs) const { return ModInt(*this) += rhs; }
ModInt operator-(const ModInt rhs) const { return ModInt(*this) -= rhs; }
ModInt operator*(const ModInt rhs) const { return ModInt(*this) *= rhs; }
ModInt operator/(const ModInt rhs) const { return ModInt(*this) /= rhs; }
ModInt &operator+=(const ModInt rhs) {
value += rhs.value;
if (value >= MOD) {
value -= MOD;
}
return *this;
}
ModInt &operator-=(const ModInt rhs) {
if (value < rhs.value) {
value += MOD;
}
value -= rhs.value;
return *this;
}
ModInt &operator*=(const ModInt rhs) {
value = value * rhs.value % MOD;
return *this;
}
ModInt &operator/=(ModInt rhs) {
*this *= rhs.inv();
return *this;
}
ModInt &operator++(int n) {
value++;
if (value >= MOD) {
value -= MOD;
}
return *this;
}
ModInt &operator--(int n) {
if (value == 0) {
value += MOD;
}
value--;
return *this;
}
ModInt inv() { return ModInt::pow(*this, MOD - 2); }
static ModInt pow(ModInt base, long long int n) {
ModInt res = ModInt(1);
while (n) {
if (n & 1) {
res *= base;
}
base *= base;
n /= 2;
}
return res;
}
static ModInt comb(ModInt n, ModInt r) { return comb(n.value, r.value); }
static ModInt comb(int n, int r) {
if (n < r)
return ModInt(0);
ModInt res = ModInt(1);
for (int i = 0; i < r; i++) {
res *= ModInt(n - i);
}
ModInt inv = ModInt(1);
for (int i = 0; i < r; i++) {
inv *= ModInt(r - i);
}
return res / inv;
}
// nC0からnCnまでを計算する。計算量はO(n)
// @param n 要素数
// @param vec 結果を格納する配列
static void combination_table(int n, std::vector<ModInt> &vec) {
assert(static_cast<int>(vec.size()) >= n + 1);
vec[0] = ModInt(1);
for (int r = 1; r < n + 1; r++) {
vec[r] = vec[r - 1] * ModInt(n - r + 1) / ModInt(r);
}
}
// n!までを計算する
// @param n 要素数
// @param vec 結果を格納する配列
static void factorial_table(int n, std::vector<ModInt> &vec) {
assert(static_cast<int>(vec.size()) >= n + 1);
vec[0] = ModInt(1);
for (int r = 1; r <= n; r++) {
vec[r] = vec[r - 1] * ModInt(r);
}
}
u64 getValue() const { return value; }
private:
u64 value;
friend std::ostream &operator<<(std::ostream &out, const ModInt<MOD> &m) {
out << m.value;
return out;
}
friend std::istream &operator>>(std::istream &in, ModInt &m) {
uint_fast64_t i;
in >> i;
m = ModInt(i);
return in;
}
};
#endif
#line 1 "/workspaces/compro/lib/template.hpp"
#line 3 "/workspaces/compro/lib/io/vector.hpp"
#ifndef IO_VECTOR
#define IO_VECTOR
template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
int size = v.size();
for (int i = 0; i < size; i++) {
std::cout << v[i];
if (i != size - 1)
std::cout << " ";
}
return out;
}
template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
for (auto &el : v) {
std::cin >> el;
}
return in;
}
#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<
using namespace std;
template <class T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
std::sort(v.begin(), v.end());
v.erase(std::unique(v.begin(), v.end()), v.end());
}
#line 3 "main.cpp"
constexpr long long MOD = 998244353;
using mint = ModInt<MOD>;
std::vector<int> prime_int_table(const int n) {
int size = n + 1;
std::vector<int> table(size, -1);
for (int i = 2; i < size; i++) {
if (table[i] != -1)
continue;
table[i] = i;
for (int k = 2; i * k < size; k++) {
if (table[i * k] == -1) {
table[i * k] = i;
}
}
}
return table;
}
mint solve(long long N) {
auto table = prime_int_table(N);
vector<int> idx(1001, -1);
vi rev;
int cp = 0;
REP(i, 1001) {
if (table[i] != i)
continue;
idx[i] = cp;
rev.push_back(i);
cp++;
}
vector<vi> memo((N + 1) / 2, vi(cp, 0));
for (int i = 1; i <= N - i; i++) {
assert(i <= (N + 1) / 2);
int tmp = i;
while (table[tmp] != -1) {
if (table[tmp] < 1000)
memo[i - 1][idx[table[tmp]]]++;
tmp /= table[tmp];
}
tmp = N - i;
while (table[tmp] != -1) {
if (table[tmp] < 1000)
memo[i - 1][idx[table[tmp]]]++;
tmp /= table[tmp];
}
}
mint ans = 1;
FOR(i, 1000, N) {
if (table[i] == i)
ans *= mint(i);
}
FOR(i, 1, (N + 1) / 2) {
REP(j, cp) { chmax(memo[i][j], memo[i - 1][j]); }
}
REP(j, cp) {
int a = memo[(N + 1) / 2 - 1][j];
ans *= mint::pow(rev[j], a);
}
return ans;
}
// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
long long N;
std::cin >> N;
auto ans = solve(N);
std::cout << ans << std::endl;
return 0;
}