結果

問題 No.3461 Min GCD
コンテスト
ユーザー umezo
提出日時 2026-03-02 07:10:26
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 1,322 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,289 ms
コンパイル使用メモリ 352,316 KB
実行使用メモリ 18,048 KB
最終ジャッジ日時 2026-03-02 07:10:36
合計ジャッジ時間 7,371 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>;
using u128=__int128_t;
using ll=long long;

const ll INF=1e13;

vector<ll> divisor(ll x){
  set<ll> s;
  for(ll i=1;i*i<=x;i++){
    if(x%i==0){
      s.insert(i);
      s.insert(x/i);
    }
  }
  vector<ll> res;
  for(auto y:s) res.push_back(y);
  return res;
}
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  VV<ll> C(100100);
  for(int i=1;i<100100;i++){
    auto a=divisor(i);
    sort(ALL(a));
    C[i]=a;
  }
  
  ll n,k;
  cin>>n>>k;
  V<ll> A(n),B(n);
  rep(i,n) cin>>A[i];
  rep(i,n) cin>>B[i];
  
  auto f=[&](int x)->bool{
    ll sum=0;
    rep(i,n){
      auto l=lower_bound(ALL(C[A[i]]),x)-C[A[i]].begin();
      if(l==C[A[i]].size()) return false;
      ll mi=INF;
      for(int j=l;j<C[A[i]].size();j++){
        ll a=C[A[i]][j];
        mi=min(mi,(B[i]+a-1)/a*a-B[i]);
      }
      sum+=mi;
    }
    if(sum<=k) return true;
    return false;
  };
  
  int ok=1,ng=100001;
  while(ng-ok>1){
    int mid=(ng+ok)/2;
    if(f(mid)) ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;
    
  return 0;
}
0