很不错的板子题。
太简单了无讲解= =
附两道板子题待刷
poj2891,n个mi不互质的裸题
poj1006,三个互质的裸题
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
#define int long long
//#define double long double
//#define double long long
#define re int
//#define void inline void
#define eps 1e-8
//#define mod 1e9+7
#define ls(p) p<<1
#define rs(p) p<<1|1
#define pi acos(-1.0)
#define pb push_back
#define mk make_pair
#define P pair < int , int >
using namespace std;
const int mod=1e9+7;
//const int inf=1e18;
const int M=1e8;
const int N=3;//??????.???? 4e8
int n;
int a[100005];
int b[100005];
int exgcd(int a,int b,int &x,int &y)
{
if(!b)
{
x=1;y=0;
return a;
}
else
{
int tx,ty;
int d=exgcd(b,a%b,tx,ty);
x=ty;y=tx-(a/b)*ty;
return d;
}
}
int China(int a[],int b[],int n)
{
int M=1,y,x=0;
for(int i=1;i<=n;++i)
M*=a[i];
for(int i=1;i<=n;++i)
{
int w=M/a[i];
int tx=0;
int t=exgcd(w,a[i],tx,y);
x=(x+w*(b[i]/t)*tx)%M;
}
return (x+M)%M;
}
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
}
int ans=China(a,b,n);
cout<<ans<<endl;
}
signed main()
{
int T=1;
// cin>>T;
for(int index=1;index<=T;index++)
{
solve();
// puts("");
}
return 0;
}
/*
input:
3
3 1
5 1
7 2
output:16
*/