#include<cstdio> #include<iostream> #include<cmath> #include<algorithm> #include<cstring> using namespace std; typedef long long LL; LL n,a[15],b[15],c[15],m[15]; LL mod = 1,tot1 = 1,tot; LL gcd(LL a,LL b,LL &x,LL &y) { if(!b) { x = 1,y = 0; return a; } LL d = exgcd(b,a % b,y,x); y -= x * (a / b); } int main() { n = read(); for(int i = 1;i <= n;i++) { a[i] = read(); mod *= a[i]; b[i] = read(); } for(int i = 1;i <= n;i++) { m[i] = mod / a[i]; LL x,y; gcd(m[i],a[i],x,y); x = (x + a[i]) % a[i]; x *= b[i]; c[i] = x * m[i]; } LL ans = 0; rep(i,1,n) ans += c[i]; ans %= mod; printf("%lld",ans); return 0; }
T2