結果
問題 | No.1529 Constant Lcm |
ユーザー |
|
提出日時 | 2021-06-04 20:54:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 569 ms / 3,000 ms |
コード長 | 1,357 bytes |
コンパイル時間 | 2,335 ms |
コンパイル使用メモリ | 223,636 KB |
最終ジャッジ日時 | 2025-01-21 22:43:32 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 |
ソースコード
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } constexpr ll mod=998244353; ll mod_pow(ll a,ll b){ a%=mod; if(b==0)return 1; if(b==1)return a; ll res=mod_pow(a,b/2)%mod; res*=res; res%=mod; if(b%2)res*=a; return res%mod; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); const int N=2e6+1; vector<int> p,lp(N); // lp[i]:iの最小素因数 lp[0]=lp[1]=-1; for(int i=2;i<lp.size();i++){ if(lp[i]==0){ lp[i]=i; p.emplace_back(i); } for(int j=0;j<p.size() and p[j]<=lp[i] and i*p[j]<=lp.size();j++){ lp[i*p[j]]=p[j]; } } int n; cin >> n; ll r=1; map<int,int> res; for(int i=1;i<=n/2;i++){ int b=i,c=n-i; map<int,int> mp; while(b>1){ mp[lp[b]]++; b/=lp[b]; } swap(b,c); while(b>1){ mp[lp[b]]++; b/=lp[b]; } for(auto p:mp){ res[p.first]=max(res[p.first],p.second); } } for(auto p:res){ (r*=mod_pow(p.first,p.second))%=mod; } cout << r << endl; }