program t; var n,i:longint; j,k,m,x,y,ans,m1:int64; a,b:array[1..10]of int64; procedure gcd(a,b:int64;var x,y:int64); var t:int64; begin if b=0 then begin x:=1;y:=0;exit; end; gcd(b,a mod b,x,y); t:=x;x:=y; y:=t-(a div b)*y; end; begin read(n); for i:=1 to n do begin read(j,k); a[i]:=int64(j); b[i]:=int64(k); end; m:=1; for i:=1 to n do m:=m*a[i]; for i:=1 to n do begin m1:=m div a[i]; gcd(m1,a[i],x,y);//ti*Mi≡1 mod mi ans:=(ans+(b[i]*x mod m)*m1 mod m)mod m; end; while ans<0 do ans:=ans+m; write(ans); end.
x≡1 mod 5
x≡2 mod 7
原文地址:http://blog.csdn.net/zz_ylolita/article/details/41788977