結果

問題 No.3461 Min GCD
コンテスト
ユーザー くらげ
提出日時 2026-01-01 18:08:01
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 906 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,302 ms
コンパイル使用メモリ 215,080 KB
実行使用メモリ 11,300 KB
最終ジャッジ日時 2026-02-28 13:02:27
合計ジャッジ時間 8,218 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 4 TLE * 1 -- * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i) = 0; i<(n); i++)

const int N = 100000;
const ll inf = 1e18;

ll gcd(ll a,ll b){
	if(a%b==0) return b;
	return gcd(b,a%b);
}

int main(){
    int n; ll k;
    cin >> n >> k;
    vector<ll> a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];

    // 制約
    assert(1<=n && n<=N);
    assert(1<=k && k<=inf);
    rep(i,n) assert(1<=a[i] && a[i]<=N);
    rep(i,n) assert(1<=b[i] && b[i]<=N);

    // 二分探索
    int ok = 1, ng = *min_element(a.begin(),a.end())+1;
    while(1<abs(ok-ng)){
        int mid = (ok+ng)/2;
        ll sum = 0; // 加算が必要な回数
        rep(i,n){
            int c = 0;
            while(gcd(a[i],b[i]+c)<mid) c++;
            sum += c;
        }
        if(sum<=k) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;

}
0