#include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; ll K; cin >> N >> K; vector A(N), B(N); for (auto &a : A) cin >> a; for (auto &b : B) cin >> b; int M = *max_element(A.begin(), A.end()); int U = *min_element(A.begin(), A.end()); // 各整数の約数を昇順で列挙 vector> divisors(M + 1); for (int d = 1; d <= M; d++) { for (int j = d; j <= M; j += d) { divisors[j].push_back(d); } } // 差分配列 vector diff(U + 2, 0); for (int i = 0; i < N; i++) { const auto &ds = divisors[A[i]]; int best = INT_MAX; // 約数を大きい順に処理 for (int j = (int)ds.size() - 1; j >= 0; j--) { int d = ds[j]; // B[i] を d の倍数にする最小操作回数 int cost = (d - B[i] % d) % d; best = min(best, cost); // この best が適用されるスコアの区間 int L = (j == 0 ? 1 : ds[j - 1] + 1); int R = min(d, U); if (L <= R) { diff[L] += best; diff[R + 1] -= best; } } } // 各スコアに必要な操作回数を計算 ll sum = 0; int ans = 1; for (int x = 1; x <= U; x++) { sum += diff[x]; if (sum <= K) { ans = x; } } cout << ans << '\n'; return 0; }