結果
| 問題 | No.3461 Min GCD |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-28 14:33:33 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 1,007 ms / 2,000 ms |
| コード長 | 1,058 bytes |
| 記録 | |
| コンパイル時間 | 3,562 ms |
| コンパイル使用メモリ | 347,928 KB |
| 実行使用メモリ | 208,936 KB |
| 最終ジャッジ日時 | 2026-02-28 14:33:44 |
| 合計ジャッジ時間 | 9,668 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#include<atcoder/modint>
using namespace atcoder;
using mint=modint998244353;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N,K;
cin>>N>>K;
vector<ll> A(N),B(N);
for(int i=0;i<N;i++)cin>>A[i];
for(int i=0;i<N;i++)cin>>B[i];
vector<vector<ll>> Y(N);
for(int i=0;i<N;i++){
for(ll x=1;x*x<=A[i];x++){
if(A[i]%x==0){
Y[i].push_back(x);
if(x*x!=A[i])Y[i].push_back(A[i]/x);
}
}
sort(Y[i].begin(),Y[i].end());
Y[i].push_back(1e18);
}
ll L=1,R=1e18;
while(R-L>1){
ll M=(R+L)/2;
ll cnt=0;
for(int i=0;i<N;i++){
ll res=1e18;
for(auto y:Y[i]){
if(y<M)continue;
ll nb=((B[i]+y-1)/y)*y;
res=min(res,nb-B[i]);
}
cnt+=res;
if(cnt>K)break;
}
if(cnt<=K)L=M;
else R=M;
}
cout<<L<<"\n";
}