标签:def source pre int div code 中国 ace clu
233
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#define inr long long
using namespace std;
inr exgcd(inr a,inr b,inr &x,inr &y)
{
if(!b)
{
x=1;
y=0;
return 0;
}
exgcd(b,a%b,x,y);
inr k=x;
x=y;
y=k-a/b*y;
return 0;
}
inr a[21],b[21];
int main()
{
inr n;
cin>>n;
inr M=1;
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
M*=a[i];
}
inr ans=0;
for(int i=1;i<=n;i++)
{
inr x,y;
exgcd(M/a[i],a[i],x,y);
ans=(ans+x*M/a[i]*b[i])%M;
}
cout<<(ans+M)%M;
}
标签:def source pre int div code 中国 ace clu
原文地址:https://www.cnblogs.com/Lance1ot/p/9113678.html