結果
問題 |
No.2718 Best Consonance
|
ユーザー |
![]() |
提出日時 | 2025-01-15 18:22:22 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 996 ms / 4,000 ms |
コード長 | 3,013 bytes |
コンパイル時間 | 4,092 ms |
コンパイル使用メモリ | 312,380 KB |
実行使用メモリ | 9,600 KB |
最終ジャッジ日時 | 2025-01-15 18:22:38 |
合計ジャッジ時間 | 12,287 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 36 |
ソースコード
#ifdef t9unkubj #include"debug.cpp" //#include"template_no_debug.h" #else #define dbg(...) 199958 #endif #undef _GLIBCXX_DEBUG #pragma GCC optimize("O3") using namespace std; #include<bits/stdc++.h> using ll=long long; using ull=unsigned long long; template<class T>using vc=vector<T>; template<class T>using vvc=vc<vc<T>>; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++) #define DREP(i,n,m) for(ll i=(n);i>=(m);i--) #define drep(i,n) for(ll i=((n)-1);i>=0;i--) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() template<class T,class F> bool chmin(T &x, F y){ if(x>y){ x=y; return true; } return false; } template<class T, class F> bool chmax(T &x, F y){ if(x<y){ x=y; return true; } return false; } double pass_time=0; template<int n> struct NUMBER{ vc<int>mf; //[1,n]まで扱う constexpr NUMBER()=default; constexpr void build(){ mf.resize(n); rep(i,n)mf[i]=i; REP(i,2,n){ if(mf[i]==i){ for(int j=i+i;j<n;j+=i)chmin(mf[j],i); } } } constexpr vc<pair<int,int>>factor(int k){ assert(k<n); vc<pair<int,int>>res; while(k!=1){ if(res.size()&&res.back().first==mf[k]){ res.back().second++; }else res.push_back({mf[k],1}); k/=mf[k]; } return res; } constexpr vc<int>divs(int k){ vc<int>ans; auto res=factor(k); auto dfs=[&](auto&dfs,int now,int now_idx)->void{ if(now_idx==res.size()){ ans.push_back(now); return; }else{ int coef=1; rep(i,res[now_idx].second+1){ dfs(dfs,now*coef,now_idx+1); coef*=res[now_idx].first; } } }; dfs(dfs,1,0); return ans; } constexpr int mebius(int k){ auto res=factor(k); for(auto[x,y]:res)if(y>=2)return 0; return res.size()%2?-1:1; } }; void solve(){ NUMBER<int(2e5)+10>nm; nm.build(); int n; cin>>n; vc<ll>a(n),b(n); rep(i,n){ cin>>a[i]>>b[i]; b[i]*=a[i]; } vc<int>idx(n); iota(all(idx),0); sort(all(idx),[&](int i,int j){ return b[i]>b[j]; }); dbg(nm.divs(36)); vc<ll>mi(2e5+1,2e13); ll ans=0; auto work=[&](int x){ auto R=nm.divs(x); for(auto&y:R){ chmin(mi[y],mi[x]); } }; using i128=__int128; for(auto i:idx){ for(auto&x:nm.divs(a[i])){ chmax(ans,i128(x)*b[i]/((i128)mi[x]*a[i])); } chmin(mi[a[i]],a[i]); work(a[i]); } cout<<ans<<"\n"; } signed main(){ cin.tie(0)->sync_with_stdio(0); pass_time=clock(); int t=1; //cin>>t; while(t--)solve(); pass_time=clock()-pass_time; dbg(pass_time/CLOCKS_PER_SEC); }