这题开 long long 90分,直接在乘法前面加了 __int128 就过了!根本不用快速乘。
#include<bits/extc++.h>
using namespace std;
#define BTS 0
#define STB 1
#define afor(i,n,m,dir) for(int i=n;dir?i<=m:i>=m;dir?i++:i--)
#define int long long
int a[101],b[101],c=1,m[101],n,x[101],su;
void eg(int a,int b,int &x,int &y){
if(!b){x=1,y=0;return;}
eg(b,a%b,y,x),y-=a/b*x;
}int ny(int x,int p){
int p1=0,q=0;
eg(x,p,p1,q);return (p1%p+p)%p;
}signed main(){
ios::sync_with_stdio(0),cin>>n;
afor(i,1,n,STB)cin>>b[i];
afor(i,1,n,STB)cin>>a[i];
afor(i,1,n,STB)b[i]=(b[i]%a[i]+a[i])%a[i],c*=a[i];
afor(i,1,n,STB)m[i]=c/a[i];
afor(i,1,n,STB)x[i]=(__int128)/*这里!!*/b[i]%c*m[i]%c*ny(m[i],a[i])%c;
afor(i,1,n,STB)su+=x[i];
cout<<su%c;return 0;
}