結果
| 問題 |
No.1529 Constant Lcm
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-06 22:47:05 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,713 bytes |
| コンパイル時間 | 1,751 ms |
| コンパイル使用メモリ | 175,764 KB |
| 実行使用メモリ | 14,752 KB |
| 最終ジャッジ日時 | 2024-07-01 12:16:35 |
| 合計ジャッジ時間 | 6,457 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 8 TLE * 1 -- * 15 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define DREP(i,s,n) for(int i = (s); i < (n); i++)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 998244353;
const double pi = acos(-1);
ll gcd(ll a, ll b) {if(b == 0) return a; else return gcd(b,a%b);}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}
map<ll,ll> f(ll N) {
map<ll,ll> mp;
for(ll i = 2; i*i <= N; i++) {
if(N%i == 0) {
ll ex = 0;
while(N%i == 0) {
ex++;
N /= i;
}
mp[i] += ex;
}
}
if(N!=1) mp[N]++;
return mp;
}
ll modpow(ll a, ll n) {
if(n == 0) return 1;
auto t = modpow(a,n/2);
t = t*t;
t %= MOD;
if(n & 1) {
t *= a;
t %= MOD;
}
return t;
}
int main() {
ll N; cin >> N;
map<ll,ll> LCM;
for(ll i = 1; i <= N-1; i++) {
map<ll,ll> mp;
for(auto e : f(i)) mp[e.first] += e.second;
for(auto e : f(N-i)) mp[e.first] += e.second;
for(auto e : mp) {
//cout << e.first << " " << e.second << endl;
LCM[e.first] = max(LCM[e.first],e.second);
}
}
ll ans = 1;
for(auto e : LCM) {
ans *= modpow(e.first, e.second);
ans %= MOD;
}
cout << ans << endl;
return 0;
}