結果
問題 | No.1529 Constant Lcm |
ユーザー |
![]() |
提出日時 | 2021-06-04 21:58:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 638 ms / 3,000 ms |
コード長 | 1,324 bytes |
コンパイル時間 | 1,617 ms |
コンパイル使用メモリ | 173,496 KB |
実行使用メモリ | 7,220 KB |
最終ジャッジ日時 | 2024-11-19 14:19:27 |
合計ジャッジ時間 | 9,181 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; using ll=long long; #define MAX 1000 #define MOD 998244353 vector<int> p; vector<bool> p_table(MAX+1,true); void prime(){ p_table.at(0)=false,p_table.at(1)=false; for(int i=2;i<=MAX;i++){ if(p_table.at(i)){ p.push_back(i); for(int j=2;i*j<=MAX;j++){ p_table.at(i*j)=false; } } } } int main(){ int N; cin>>N; prime(); int n=p.size(); vector<int> cnt(n,0); vector<int> other_p(N,0); for(int i=1;i<=N/2;i++){ int x=i; int y=N-i; for(int j=0;j<n;j++){ int counter=0; while(x%p[j]==0){ counter++; x/=p[j]; } while(y%p[j]==0){ counter++; y/=p[j]; } cnt[j]=max(cnt[j],counter); } if(x>1&&y>1){ if(x==y){ other_p[x]=2; }else{ other_p[x]=max(1,other_p[x]); other_p[y]=max(1,other_p[y]); } }else if(x>1){ other_p[x]=max(1,other_p[x]); }else if(y>1){ other_p[y]=max(1,other_p[y]); } } ll ans=1; for(int i=0;i<n;i++){ for(int j=0;j<cnt[i];j++){ ans*=(ll)p[i]; ans%=MOD; } } for(int i=1;i<N;i++){ for(int j=0;j<other_p[i];j++){ ans*=(ll)i; ans%=MOD; } } cout<<ans<<endl; }