結果
| 問題 |
No.1529 Constant Lcm
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2021-12-17 07:44:02 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,656 bytes |
| コンパイル時間 | 1,644 ms |
| コンパイル使用メモリ | 144,616 KB |
| 実行使用メモリ | 38,296 KB |
| 最終ジャッジ日時 | 2024-09-14 07:47:30 |
| 合計ジャッジ時間 | 6,628 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 8 TLE * 1 -- * 15 |
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
class Prime {
public:
vector<ll> prime_list;
const ll MAX_N = 1000000;
Prime() {
bool checked[MAX_N + 1];
memset(checked, false, sizeof(checked));
for (ll i = 2; i <= MAX_N; ++i) {
if (!checked[i]) {
prime_list.push_back(i);
for (ll j = i * i; j <= MAX_N; j += i) {
checked[j] = true;
}
}
}
}
map<ll, int> prime_division(ll n) {
map<ll, int> res;
for (ll i = 0; prime_list[i] <= sqrt(n); ++i) {
assert(i < prime_list.size());
ll p = prime_list[i];
while (n % p == 0) {
++res[p];
n /= p;
}
}
if (n != 1) {
res[n] = 1;
}
return res;
}
bool is_prime(ll n) {
if (n <= 1) return false;
for (int i = 0; i < prime_list.size(); ++i) {
if (n % prime_list[i]) return false;
}
return true;
}
};
int main() {
ll N;
cin >> N;
Prime prime;
vector<int> counter(N + 1, 0);
map<ll, bool> checked;
for (ll i = 1; i <= N - 1; ++i) {
ll a = i * (N - i);
if (checked[a]) continue;
checked[a] = true;
map<ll, int> res = prime.prime_division(a);
for (auto e : res) {
counter[e.first] = max(counter[e.first], e.second);
}
}
ll ans = 1;
for (int i = 1; i < N; ++i) {
if (counter[i] == 0) continue;
ans *= pow(i, counter[i]);
ans %= MOD;
}
cout << ans << endl;
return 0;
}
siman