#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int __int128
inline int read(){
int x = 0,f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if(ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
void write(int x)
{
if(x<0)
putchar('-'),x=-x;
if(x>9)
write(x/10);
putchar(x%10+'0');
return;
}
int k, a[15], b[15], mul=1, M[15], ny[15], ans;
void Exgcd(int a, int b, int &x, int &y){
if(!b){
x = 1, y = 0;
return ;
}
else{
Exgcd(b, a % b, x, y);
int z = x, x = y, y = z - (a / b) * y;
}
}
signed main(){
k = read();
for(int i = 1; i <= k; ++i) a[i] = read();
for(int i = 1; i <= k; ++i){
b[i] = read();
mul *= b[i];
}
for(int i = 1; i <= k; ++i){
a[i] = (a[i] % b[i] + b[i]) % b[i];
M[i] = mul / b[i];
int x, y;
Exgcd(M[i], b[i], x, y);
x = (x % b[i] + b[i]) % b[i];
ny[i] = x;
ans += (a[i] * M[i] * ny[i] % mul);
ans %= mul;
}
write(ans % mul);
return 0;
}
感谢。