#include <iostream> #include <algorithm> #include <cstring> #include <cmath> using namespace std; #define int long long int n,a[20],M[20],Mi[20]; int gcd(int a,int b,int &x,int &y){ if (b == 0){ x=1; y=0; return a; } int t = gcd(b,a%b,y,x); y -= a/b*x; return t; } void sov(){ int xx=1; for(int i=1;i<=n;i++){ cin>>M[i]>>a[i]; xx*=M[i]; } int ans= 0; for(int i=1;i<=n;i++){ Mi[i]=xx/M[i]; int x=0,y=0; gcd(Mi[i],M[i],x,y) ; ans+= a[i]*Mi[i]* ((x+M[i])%M[i]) ; } cout << ans%xx <<endl; } signed main(){ cin>>n; sov() ; }
标签:曹冲,P1495,CRT,int,xx,sov,20,include From: https://www.cnblogs.com/towboa/p/17356962.html