#yukicoder 187 中華風(Hard) 多倍長解法 #exec gcd #Reference: https://x.com/_miz_tom/status/1842086118990479854 exec('def gcd(x, y):\n' + ' x, y = abs(x), abs(y)\n' + ' if x == 0: return y\n' + ' if not (y := y % x): return x\n if not (x := x % y): return y\n' * 300 + ' return gcd(x, y)') #exec gcdを使わない版 gcd = lambda x, y: gcd(y, x % y) if y else abs(x) def CRT(m1, M1, m2, M2): #smallest n ≡ m1 mod M1 ≡ m2 mod M2 if (m1 - m2) % ( G := gcd(M1, M2) ) != 0: return -1 return (m2 - m1) * pow(M1 // G, -1, M2 // G) % M2 * M1 // G + m1 #入力受取 N = int(input()) P = [tuple(map(int, input().split())) for _ in range(N)] MOD = 10 ** 9 + 7 #CRTを実行 rem, mod = 0, 1 for Xi, Yi in P: rem = CRT(rem, mod, Xi, Yi) if rem == -1: break mod = mod * Yi // gcd(mod, Yi) if rem == -1: #解なし print(-1) elif rem == 0: #正整数を探す → lcm(Yi) print(mod % MOD) else: #remを出力 print(rem % MOD)