#include #include using namespace std; using namespace atcoder; using mint = modint998244353; //using mint = modint1000000007; typedef long long ll; typedef pair P; // typedef tuple T; templatebool chmax(T& a, const T& b) { if (a < b) { a = b;return true; } else { return false; } } templatebool chmin(T& a, const T& b) { if (a > b) { a = b;return true; } else { return false; } } template void dbg(Args&&... args) { ((cout << args << ' '), ...);cout << '\n'; } const int di[] = { -1,0,1,0 }; const int dj[] = { 0,-1,0,1 }; const long long INF = 6000000000000000000; const int inf = 1001001001; int main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; ll k; cin >> k; vector a(n, 0), b(n, 0); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } vector> c(n); using T = tuple; priority_queue, greater> pq; for (int j = 0; j < n; j++) { ll g = gcd(a[j], b[j]); for (long long i = g; i * i <= a[j]; ++i) { if (a[j] % i == 0) { c[j].insert(i); // 重複しないならば i の相方である N/i も push if (a[j] / i != i)c[j].insert(a[j] / i); } } pq.emplace(g, j); } int ans = inf; while (pq.size()) { auto [g, p] = pq.top();pq.pop(); // dbg(g, p, k); auto it = c[p].find(g); it++; int x = *it; int cnt = b[p] % x; if (k - (x - cnt) >= 0)k -= x - cnt; else break; b[p] += x - cnt; ll h = gcd(a[p], b[p]); // dbg(h, p); if (h == a[p])continue; pq.emplace(h, p); } for (int i = 0; i < n; i++) { chmin(ans, gcd(a[i], b[i])); } cout << ans << "\n"; }