#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 500010;
int n, m, a[MAXN], b[MAXN];
signed main() {
freopen("gcdlcm.in", "r", stdin);
freopen("gcdlcm.out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i ++) {
cin >> a[i];
}
for(int i = 1; i <= n; i ++) {
cin >> b[i];
}
for(int i = 1; i <= m; i ++) {
int op, x, y, w;
cin >> op >> x >> y;
if(op == 1) {
cin >> w;
for(int j = x; j <= y; j ++) {
a[j] = w;
}
}
else {
int minn = 1e12;
for(int j = x; j <= y; j ++) {
w = __gcd(a[j], b[j]);
minn = min(minn, a[j] * b[j] / w / w);
}
cout << minn << endl;
}
}
return 0;
}