結果
問題 | No.1529 Constant Lcm |
ユーザー | Haa |
提出日時 | 2021-06-04 20:20:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,650 ms / 3,000 ms |
コード長 | 1,182 bytes |
コンパイル時間 | 1,692 ms |
コンパイル使用メモリ | 178,512 KB |
実行使用メモリ | 195,736 KB |
最終ジャッジ日時 | 2024-11-19 08:45:47 |
合計ジャッジ時間 | 19,031 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll,ll> P; typedef vector<ll> VI; typedef vector<VI> VVI; #define REP(i,n) for(ll i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() constexpr ll MOD=998244353; constexpr ll INF=2e18; ll power(ll x, ll y){ x%=MOD; ll ret=1; while(y){ if(y&1) ret=ret*x%MOD; x=x*x%MOD; y>>=1; } return ret; } int main(){ int n; cin >> n; vector<map<int,int>> mp(n+1); VI f(n+1,0); for(int i=2;i<=n;i++){ if(f[i]) continue; for(int j=i;j<=n;j+=i){ f[j]=1; int x=j; while(x%i==0){ x/=i; mp[j][i]++; } } } vector<int> cnt(n+1,0); for(int i=1;i<n;i++){ map<int,int> mps; for(auto p:mp[i]){ mps[p.first]+=p.second; } for(auto p:mp[n-i]){ mps[p.first]+=p.second; } for(auto p:mps){ cnt[p.first]=max(cnt[p.first],p.second); } } ll ans=1; for(int i=2;i<=n;i++){ ans=ans*power(i,cnt[i])%MOD; } cout << ans << endl; return 0; }