#include // #include namespace cho { std::vector prime_table(int n) { std::vector p(n + 1, -1); for (int i = 2; i * i <= n; i++) { if (p[i] != -1) continue; for (int j = i * i; j <= n; j += i) p[j] = i; } return p; } std::map table_factor(int n) { const static std::vector table = prime_table(1e7); assert(n <= 1e7); std::map res; while (n > 1) { if (table[n] == -1) { res[n]++; break; } res[table[n]]++; n /= table[n]; } return res; } std::vector all_factors(int n) { assert(n <= 1e7); std::vector res = {1}; int sz = 1; for (auto [x, ad] : table_factor(n)) { for (int i = 0; i < ad * sz; i++) { res.push_back(res[i] * x); } sz *= ad + 1; } return res; } } // namespace cho using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } void solve() { ll n, k; cin >> n >> k; vector a(n), b(n); rep(i, 0, n) cin >> a[i]; rep(i, 0, n) cin >> b[i]; vector>> da(n); int up = 1e9; int dw = 1; rep(i, 0, n) { auto v = cho::all_factors(a[i]); sort(all(v)); for (int x : v) { int ct = (x - b[i] % x) % x; while (!da[i].empty() && da[i].back().second >= ct) da[i].pop_back(); da[i].push_back({x, ct}); } chmin(up, a[i]); } up++; while (up - dw > 1) { int md = (up + dw) / 2; ll tk = 0; rep(i, 0, n) { auto [x, ct] = *lower_bound(all(da[i]), pair(md, -1)); tk += ct; } if (tk <= k) dw = md; else up = md; } cout << dw << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int t = 1; // cin >> t; while (t--) solve(); }